]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: use cheaper randoms for fault injections
authorWilly Tarreau <w@1wt.eu>
Sat, 17 Apr 2021 13:50:28 +0000 (15:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 Apr 2021 13:24:33 +0000 (15:24 +0200)
ha_random() is quite heavy and uses atomic ops or even a lock on some
architectures. Here we don't seek good randoms, just statistical ones,
so let's use the statistical prng instead.

src/pool.c

index db5d931015ada9fbacfb3a0fc938bcdac9d77f53..48cc46788bf788b1e024021332654d53177ca4c0 100644 (file)
@@ -498,9 +498,7 @@ int mem_should_fail(const struct pool_head *pool)
        int ret = 0;
 
        if (mem_fail_rate > 0 && !(global.mode & MODE_STARTING)) {
-               int randnb = ha_random() % 100;
-
-               if (mem_fail_rate > randnb)
+               if (mem_fail_rate > statistical_prng_range(100))
                        ret = 1;
                else
                        ret = 0;