[master] 849c08441 http1: Optionally honor thread_stats_rate
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Jan 11 17:06:08 UTC 2021
commit 849c084417066c1f7fdb9421943143a0ade22c32
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Oct 20 17:33:07 2020 +0200
http1: Optionally honor thread_stats_rate
When a session is continuously used, for example in a multi-tier setup,
it can take a very long time before an HTTP/1 session runs out of tasks
and unwinds back to the point where the worker might update its stats.
This phenomenon is amplified by thread_stats_rate, so it might take even
longer to get statistics published. This is famously observed with load
testing campaigns where a certain set of VSCs may not increase at all
until the very end of a load run.
This change makes it possible for HTTP/1 sessions to at least publish
their statistics into the pool every thread_stats_rate requests.
To avoid a potential performance cost, this behavior (technically
complying with the documentation) is guarded by a feature flag. The
flag is generic so this behavior may be extended to other busy loops,
present (if any) or future.
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 96fb33ff8..70dcdb8ba 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -478,6 +478,7 @@ void VMOD_Panic(struct vsb *);
/* cache_wrk.c */
void WRK_Init(void);
+void WRK_AddStat(struct worker *);
/* cache_ws.c */
void WS_Id(const struct ws *ws, char *id);
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index ee0185146..0fbe71229 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -169,6 +169,25 @@ pool_addstat(struct VSC_main_wrk *dst, struct VSC_main_wrk *src)
memset(src, 0, sizeof *src);
}
+void
+WRK_AddStat(struct worker *wrk)
+{
+ struct pool *pp;
+
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ pp = wrk->pool;
+ CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
+ if (++wrk->stats->summs >= cache_param->wthread_stats_rate) {
+ Lck_Lock(&pp->mtx);
+ pool_addstat(pp->a_stat, wrk->stats);
+ Lck_Unlock(&pp->mtx);
+ }
+}
+
+/*--------------------------------------------------------------------
+ * Pool reserve calculation
+ */
+
static unsigned
pool_reserve(void)
{
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 6a339f5a4..393088520 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -414,6 +414,8 @@ HTTP1_Session(struct worker *wrk, struct req *req)
HTC_RxInit(req->htc, req->ws);
if (req->htc->rxbuf_e != req->htc->rxbuf_b)
wrk->stats->sess_readahead++;
+ if (FEATURE(FEATURE_BUSY_STATS_RATE))
+ WRK_AddStat(wrk);
http1_setstate(sp, H1NEWREQ);
} else {
WRONG("Wrong H1 session state");
diff --git a/include/tbl/feature_bits.h b/include/tbl/feature_bits.h
index 207e18e11..d51b22cef 100644
--- a/include/tbl/feature_bits.h
+++ b/include/tbl/feature_bits.h
@@ -78,6 +78,10 @@ FEATURE_BIT(VALIDATE_HEADERS, validate_headers,
"Validate all header set operations to conform to RFC7230."
)
+FEATURE_BIT(BUSY_STATS_RATE, busy_stats_rate,
+ "Make busy workers comply with thread_stats_rate."
+)
+
#undef FEATURE_BIT
/*lint -restore */
More information about the varnish-commit
mailing list