]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: freq_ctr: use the thread's local time whenever possible
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Oct 2022 09:55:16 +0000 (11:55 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Oct 2022 12:19:05 +0000 (14:19 +0200)
commitf6a42c3a371b764d7e841d07cb709a51b22beb84
tree3c476653383445481e839297f06c4b82a9eeb41d
parentb13044cc1ac04ed4239030f9e600b9301ac531be
MINOR: freq_ctr: use the thread's local time whenever possible

Right now when dealing with freq_ctr updates, we're using the process-
wide monotinic time, and accessing it is expensive since every thread
needs to update it, so this adds some contention. However we don't need
it all the time, the thread's local time is most of the time strictly
equal to the global time, and may be off by one millisecond when the
global time is switched to the next one by another thread, and in this
case we don't want to use the local time because it would risk to cause
a rotation of the counter. But that's precisely the condition we're
already relying on for the slow path!

What this patch does is to add a check for the period against the
local time prior to anything else, and immediately return after
updating the counter if still within the period, otherwise fall back
to the existing code. Given that the function starts to inflate a bit,
it was split between s very short inline part that does the hot path,
and the slower fallback that's in a cold function. It was measured that
on a 24-CPU machine it was called ~0.003% of the time.

The resulting improvement sits between 2 and 3% at 500k req/s tracking
an http_req_rate counter.
include/haproxy/freq_ctr.h
src/freq_ctr.c