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.
This commit is contained in:
Willy Tarreau 2022-06-23 18:31:08 +02:00
parent 962e5ba72b
commit 555c192d14

View File

@ -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);
}
}