]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: stick-table: only take the lock when needed in stktable_touch_with_exp()
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Oct 2022 18:31:04 +0000 (18:31 +0000)
committerWilly Tarreau <w@1wt.eu>
Wed, 12 Oct 2022 12:19:05 +0000 (14:19 +0200)
commita7536ef9e1b5b8b83bc854fab53024e8cf61a6c4
treec07692f17a23a880f12029ff42812679e78b18ef
parent9f5cb435b650b19eba37e438bfde6a8b98a64fb1
MEDIUM: stick-table: only take the lock when needed in stktable_touch_with_exp()

As previously mentioned, this function currently holds an exclusive lock
on the table during all the time it take to check if the entry needs to
be updated and synchronized with peers. The reality is that many setups
do not use peers and that on highly loaded setups, the same entries are
hammered all the time so the key's expiration doesn't change between a
number of consecutive accesses.

With this patch we take a different approach. The function starts
without taking the lock, and will take it only if needed, keeping track
of it. This way we can avoid it most of the time, or even entirely.
Finally if the decrefcnt argument requires that the refcount is
decremented, we either do it using a non-atomic op if the table was
locked (since no other entry may touch it) or via an atomic under the
read lock only.

With this change alone, a 48-thread test with 3 trackers increased
from 193k req/s to 425k req/s, which is a 2.2x factor.
src/stick_table.c