]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: stick-table: change the ref_cnt atomically
authorWilly Tarreau <w@1wt.eu>
Sat, 27 May 2023 16:55:48 +0000 (16:55 +0000)
committerWilly Tarreau <w@1wt.eu>
Fri, 11 Aug 2023 17:03:35 +0000 (19:03 +0200)
commit7968fe38895ba36ac1d1382555abaa1b64b81a5a
treea6f0a9faeb4491b848e414171f9699fffd86478f
parent73b1dea4d104d38e22cc898cf12499a778bd754e
MEDIUM: stick-table: change the ref_cnt atomically

Due to the ts->ref_cnt being manipulated and checked inside wrlocks,
we continue to have it updated under plenty of read locks, which have
an important cost on many-thread machines.

This patch turns them all to atomic ops and carefully moves them outside
of locks every time this is possible:
  - the ref_cnt is incremented before write-unlocking on creation otherwise
    the element could vanish before we can do it
  - the ref_cnt is decremented after write-locking on release
  - for all other cases it's updated out of locks since it's guaranteed by
    the sequence that it cannot vanish
  - checks are done before locking every time it's used to decide
    whether we're going to release the element (saves several write locks)
  - expiration tests are just done using atomic loads, since there's no
    particular ordering constraint there, we just want consistent values.

For Lua, the loop that is used to dump stick-tables could switch to read
locks only, but this was not done.

For peers, the loop that builds updates in peer_send_teachmsgs is extremely
expensive in write locks and it doesn't seem this is really needed since
the only updated variables are last_pushed and commitupdate, the first
one being on the shared table (thus not used by other threads) and the
commitupdate could likely be changed using a CAS. Thus all of this could
theoretically move under a read lock, but that was not done here.

On a 80-thread machine with a peers section enabled, the request rate
increased from 415 to 520k rps.
include/haproxy/stick_table.h
src/hlua_fcn.c
src/peers.c
src/stick_table.c