From: Willy Tarreau Date: Thu, 23 Jun 2022 16:31:08 +0000 (+0200) Subject: MINOR: poller: update_fd_polling: wake a random other thread X-Git-Tag: v2.7-dev2~133 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=555c192d14ce0bf3caefc0b1b38959e6b6f858a8;p=thirdparty%2Fhaproxy.git MINOR: poller: update_fd_polling: wake a random other thread 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. --- diff --git a/src/fd.c b/src/fd.c index 426afb5a63..56fa292ecf 100644 --- 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); } }