BUG/MINOR: tools: seed the statistical PRNG slightly better
Thomas Baroux reported a very interesting issue. "balance random" would
systematically assign the same server first upon restart. That comes from
its use of statistical_prng() which is only seeded with the thread number,
and since at low loads threads are assigned to incoming connections in
round robin order, practically speaking, the same thread always gets the
same request and will produce the same random number.
We already have a much better RNG that's also way more expensive, but we
can use it at boot time to seed the PRNG instead of using the thread ID
only.
This needs to be backported to 2.4.
(cherry picked from commit 7151076522eface09dc3268e9d12286ff570e9b0)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9ac8aa65b0f31453786e798fd2a9f7d5f5cd210d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit e936aaf7a6b77d17175cd5329c9dfe777c9438c0)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit d9636e0ab8b7d03a8c73003dba212c7210402fd3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 423b64363c10b0084d94de0711547a0c6982ea68)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/tools.c b/src/tools.c
index 89e75ef..d110598 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -5767,7 +5767,7 @@
static int init_tools_per_thread()
{
/* Let's make each thread start from a different position */
- statistical_prng_state += tid * MAX_THREADS;
+ statistical_prng_state += ha_random32();
if (!statistical_prng_state)
statistical_prng_state++;
return 1;