From: Ubuntu Date: Mon, 1 Mar 2021 07:57:54 +0000 (+0000) Subject: OPTIM: lb-random: use a cheaper PRNG to pick a server X-Git-Tag: v2.4-dev11~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1adaddb494e16f365955af52785e31e522af55bd;p=thirdparty%2Fhaproxy.git OPTIM: lb-random: use a cheaper PRNG to pick a server The PRNG used by the "random" LB algorithm was the central one which tries hard to produce "correct" (i.e. hardly predictable) values suitable for use in UUIDs or cookies. It's much too expensive for pure load balancing where a cheaper thread-local PRNG is sufficient, and the current PRNG is part of the hot places when running with many threads. Let's switch to the stastistical PRNG instead, it's thread-local, very fast, and with a period of (2^32)-1 which is more than enough to decide on a server. --- diff --git a/src/backend.c b/src/backend.c index 88531e7f25..54a4c1755e 100644 --- a/src/backend.c +++ b/src/backend.c @@ -535,7 +535,7 @@ static struct server *get_server_rnd(struct stream *s, const struct server *avoi curr = NULL; do { prev = curr; - hash = ha_random32(); + hash = statistical_prng(); curr = chash_get_server_hash(px, hash, avoid); if (!curr) break;