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.
diff --git a/src/lb_chash.c b/src/lb_chash.c
index a37a40f..709105c 100644
--- a/src/lb_chash.c
+++ b/src/lb_chash.c
@@ -324,7 +324,7 @@
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 @@
}
out:
- HA_RWLOCK_WRUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
+ HA_RWLOCK_RDUNLOCK(LBPRM_LOCK, &p->lbprm.lock);
return nsrv;
}