From: Willy Tarreau Date: Tue, 8 Nov 2016 21:03:00 +0000 (+0100) Subject: MINOR: stream: make option contstats usable again X-Git-Tag: v1.7-dev6~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=def0d22cc54229072a8abb6a850e6805208790f5;p=thirdparty%2Fhaproxy.git MINOR: stream: make option contstats usable again Quite a lot of people have been complaining about option contstats not working correctly anymore since about 1.4. The reason was that one reason for the significant performance boost between 1.3 and 1.4 was the ability to forward data between a server and a client without waking up the stream manager. And we couldn't afford to force sessions to constantly wake it up given that most of the people interested in contstats are also those interested in high performance transmission. An idea was experimented with in the past, consisting in limiting the amount of transmissible data before waking it up, but it was not usable on slow connections (eg: FTP over modem lines, RDP, SSH) as stats would be updated too rarely if at all, so that idea was dropped. During a discussion today another idea came up : ensure that stats are updated once in a while, since it's the only thing that matters. It happens that we have the request channel's analyse_exp timeout that is used to wake the stream up after a configured delay, and that by definition this timeout is not used when there's no more analyser (otherwise the stream would wake up and the stats would be updated). Thus here the idea is to reuse this timeout when there's no analyser and set it to now+5 seconds so that a stream wakes up at least once every 5 seconds to update its stats. It should be short enough to provide smooth traffic graphs and to allow to debug outputs of "show sess" more easily without inflicting too much load even for very large number of concurrent connections. This patch is simple enough and safe enough to be backportable to 1.6 if there is some demand. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 01a07646d0..b5127d6382 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -5187,9 +5187,11 @@ option contstats only when a session finishes. It works quite well when serving small objects, but with big ones (for example large images or archives) or with A/V streaming, a graph generated from haproxy counters looks like - a hedgehog. With this option enabled counters get incremented continuously, - during a whole session. Recounting touches a hotpath directly so - it is not enabled by default, as it has small performance impact (~0.5%). + a hedgehog. With this option enabled counters get incremented frequently + along the session, typically every 5 seconds, which is often enough to + produce clean graphs. Recounting touches a hotpath directly so it is not + not enabled by default, as it can cause a lot of wakeups for very large + session counts and cause a small performance drop. option dontlog-normal diff --git a/src/stream.c b/src/stream.c index 738a23ccc3..26f7a4c15f 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2367,8 +2367,14 @@ struct task *process_stream(struct task *t) /* Note: please ensure that if you branch here you disable SI_FL_DONT_WAKE */ t->expire = tick_first(tick_first(req->rex, req->wex), tick_first(res->rex, res->wex)); - if (req->analysers) - t->expire = tick_first(t->expire, req->analyse_exp); + if (!req->analysers) + req->analyse_exp = TICK_ETERNITY; + + if ((sess->fe->options & PR_O_CONTSTATS) && (s->flags & SF_BE_ASSIGNED) && + (!tick_isset(req->analyse_exp) || tick_is_expired(req->analyse_exp, now_ms))) + req->analyse_exp = tick_add(now_ms, 5000); + + t->expire = tick_first(t->expire, req->analyse_exp); if (si_f->exp) t->expire = tick_first(t->expire, si_f->exp);