commit 683f3568394a2202c29a552816d3f01c04ca3363
parent 7922bbd7a9561fc3f8ebd6f5cecdc288dcd4457f
Author: kzangeli <kzangeli@gmail.com>
Date: Wed, 18 Nov 2026 19:27:01 +0100
MHD_epoll: do not wait again after a full batch of events
The drain loop in MHD_epoll() calls epoll_wait() again as long as one
returns a full batch (MAX_EVENTS), and every call used the full
timeout. When a full batch was the last of the pending events, the
next call blocked for the whole timeout. With edge-triggered
connections that each wait for their response nothing new can arrive
meanwhile, so all connections stalled until the clients gave up:
256, 257 and 512 keep-alive connections opened at once gave
270-1800 req/s instead of ~165000.
The first call waits as before; the following ones only drain what
is pending.
Diffstat:
1 file changed, 5 insertions(+), 0 deletions(-)
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
@@ -5865,6 +5865,11 @@ MHD_epoll (struct MHD_Daemon *daemon,
events,
MAX_EVENTS,
timeout_ms);
+ /* A full batch may have been the last of the pending events: the next
+ call only drains what is left, it must not wait. With edge-triggered
+ connections nothing new arrives until they are processed, so waiting
+ here would stall every connection until the timeout. */
+ timeout_ms = 0;
if (-1 == num_events)
{
const int err = MHD_socket_get_error_ ();