]> git.kaiwu.me - haproxy.git/commit
OPTIM: lb-chash: don't look for more servers when there is only one
authorWilly Tarreau <w@1wt.eu>
Fri, 13 Nov 2026 10:06:31 +0000 (11:06 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 13 Nov 2026 16:31:34 +0000 (17:31 +0100)
commitd9550ce4f300dc4b0a2b076da65a2e1978fbdf62
treef678ac5f179976fd40c5713b6a55d9e307e57322
parent7c6159a28de1e3913deb601ad1ba5017adf9c027
OPTIM: lb-chash: don't look for more servers when there is only one

The chash_get_server_hash() function never makes a special case for a
single server. Worse, when asked to avoid a specific one and it is the
only one, or when the chosen server is not eligible, the function will
run over all its positions at the end. Thus having a single server in
a config with a weight 256 and asking to avoid it burns a lot of CPU.

Let's just test for this case after picking the first server. If the
total servers count is 1, we can just leave.
src/lb_chash.c