Commit 849c0844 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent 244c06a0
......@@ -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);
......
......@@ -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)
{
......
......@@ -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");
......
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment