MINOR: lb/chash: use a read lock in chash_get_server_hash()

When using a low hash-balance-factor value, it's possible to loop
many times trying to find the best server. Figures in the order of
100-300 times were observed for 1000 servers with a factor of 101
(which seems a bit excessive for such a large farm). Given that
there's nothing in that function that prevents multiple threads
from working in parallel, let's switch to a read lock. Tests on
8 threads show roughly a 2% performance increase with this.
This commit is contained in:
Willy Tarreau 2020-10-17 20:15:49 +02:00
parent f76a21f78c
commit 4b6e3c284a

View File

@ -324,7 +324,7 @@ struct server *chash_get_server_hash(struct proxy *p, unsigned int hash, const s
unsigned int dn, dp;
int loop;
HA_RWLOCK_WRLOCK(LBPRM_LOCK, &p->lbprm.lock);
HA_RWLOCK_RDLOCK(LBPRM_LOCK, &p->lbprm.lock);
if (p->srv_act)
root = &p->lbprm.chash.act;
@ -379,7 +379,7 @@ struct server *chash_get_server_hash(struct proxy *p, unsigned int hash, const s
}
out:
HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
return nsrv;
}