]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: poller: update_fd_polling: wake a random other thread
authorWilly Tarreau <w@1wt.eu>
Thu, 23 Jun 2022 16:31:08 +0000 (18:31 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 Jul 2022 17:15:14 +0000 (19:15 +0200)
When enabling an FD that's only bound to another thread, instead of
always picking the first one, let's pick a random one. This is rarely
used (enabling a frontend, or session rate-limiting period ending),
and has greater chances of avoiding that some obscure corner cases
could degenerate into a poorly distributed load.

src/fd.c

index 426afb5a63e135c859f000a3d156007d8454e18c..56fa292ecfa8a37e34df3e67ae9cf390b8e9ccd1 100644 (file)
--- a/src/fd.c
+++ b/src/fd.c
@@ -449,9 +449,11 @@ void updt_fd_polling(const int fd)
                fd_add_to_fd_list(&update_list, fd, offsetof(struct fdtab, update));
 
                if (fd_active(fd) && !(fdtab[fd].thread_mask & tid_bit)) {
-                       /* we need to wake up one thread to handle it immediately */
-                       int thr = my_ffsl(fdtab[fd].thread_mask & ~tid_bit & all_threads_mask) - 1;
-
+                       /* we need to wake up another thread to handle it immediately, any will fit,
+                        * so let's pick a random one so that it doesn't always end up on the same.
+                        */
+                       int thr = one_among_mask(fdtab[fd].thread_mask & all_threads_mask,
+                                                statistical_prng_range(MAX_THREADS));
                        wake_thread(thr);
                }
        }