]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM: lb-random: use a cheaper PRNG to pick a server
authorUbuntu <ubuntu@ip-172-31-37-79.us-east-2.compute.internal>
Mon, 1 Mar 2021 07:57:54 +0000 (07:57 +0000)
committerWilly Tarreau <w@1wt.eu>
Fri, 5 Mar 2021 07:30:08 +0000 (08:30 +0100)
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

index 88531e7f257b8a610fc07cc1ff50dded56cadcd7..54a4c1755e0dfd194ba4f41d1b95dca3a9a12fd7 100644 (file)
@@ -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;