From 1adaddb494e16f365955af52785e31e522af55bd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 1 Mar 2021 07:57:54 +0000 Subject: [PATCH] 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. --- src/backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend.c b/src/backend.c index 88531e7f2..54a4c1755 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;