MINOR: lb/leastconn: only take a read lock in fwlc_get_next_server()
authorWilly Tarreau <w@1wt.eu>
Sat, 17 Oct 2020 17:32:09 +0000 (19:32 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 17 Oct 2020 17:37:40 +0000 (19:37 +0200)
commit58bc9c1ced43b7802200d4d71e0eb5f850e0e801
tree07af38e4c6757a152e8d74a444b207505c871d1a
parentae99aeb135ac18b1442ddf9eeccb16cb35d2d04d
MINOR: lb/leastconn: only take a read lock in fwlc_get_next_server()

This function doesn't change the tree, it only looks for the first
usable server, so let's do that under a read lock to limit the
situations like the ones described in issue #881 where finding a
usable server when dealing with lots of saturated ones can be
expensive. At least threads will now be able to look up in
parallel.

It's interesting to note that s->served is not incremented during the
server choice, nor is the server repositionned. So right now already,
nothing prevents multiple threads from picking the same server. This
will not cause a significant imbalance anyway given that the server
will automatically be repositionned at the right place, but this might
be something to improve in the future if it doesn't come with too high
a cost.

It also looks like the way a server's weight is updated could be
revisited so that the write lock gets tighter at the expense of a
short part of inconsistency between weights and servers still present
in the tree.
src/lb_fwlc.c