ylavic commented on PR #80:
URL: https://github.com/apache/apr/pull/80#issuecomment-7313650962

   I started working on a new async MPM (mpm_async), which should eventually 
work on Windows too with a scalable apr_pollset implementation, but 
WSAEventSelect() plus a thread pool wait per socket doesn't seem to be enough 
for that:
   
   1. Cost per event and per socket: each socket holds an event object and a 
thread pool wait, and each event goes through a thread pool callback, 
WSAEnumNetworkEvents() and a post before the poller sees it. The POLLOUT 
emulation also select()s every socket waiting for APR_POLLOUT at each poll, 
which is O(n) per call.
   
   2. WSAEventSelect() puts the socket in non-blocking mode, and while it's 
registered ioctlsocket(FIONBIO) fails with WSAEINVAL. APR's Windows 
apr_socket_timeout_set() switches blocking modes with ioctlsocket() (any 
timeout other than 0 makes the socket blocking), so a socket in the pollset 
can't change its timeout, which httpd does all the time. After the removal 
(WSAEventSelect(s, NULL, 0)) the socket also stays non-blocking while APR still 
thinks it's blocking, so a later blocking recv/send returns WSAEWOULDBLOCK.
   
   3. No APR_POLLONESHOT/APR_POLLET/APR_POLLRDHUP, which an event-driven MPM 
and the pollers rely on.
   
   Two more things on this PR:
   - Moving the wakeup into each backend: the wakeup pipe handling was shared 
on purpose (pollset.c/pollcb.c and wakeup.c, 
r1940854/0b5f06c0ddd984d612e8f107182d20f90b801e79); with a `wakeup` op per 
provider it's copied back into epoll, kqueue, port, poll, select and z_asio, 
but only poll.c and select.c create the pipe, so the others call 
apr_file_putc() on a pipe that doesn't exist (that's the testpoll crash in the 
Linux CI jobs). Could the Windows backend override only its own wakeup (posting 
to the port) and leave the shared code for the others, e.g. with the new op 
NULL meaning the shared pipe?
   - The provider structs don't set `method` and `options` 
(r1940829/ca2347b2e550d7369374054cb47a6260cbc6d200), so 
apr_pollset_method_get() and apr_poll_method_options() report nothing for iocp, 
not even APR_POLLIN/APR_POLLOUT.
   
   For my work I tried two ways on Windows VMs:
   
   - IOCP with ProcessSocketNotifications() (build 20348+: Server 2022, Windows 
11): it's documented and maps to one-shot/edge/level and RDHUP, but I hit its 
limits with several threads polling (apr_pollset_poller_poll()): a socket's 
REMOVE notification can be queued after later completions, the socket's 
re-registration is refused (WSAEINVAL) until well after that, and a one-shot 
registration can be notified several times. A testpoll case removing and 
re-adding a one-shot socket while 8 pollers poll fails every run. A socket is 
also bound to one completion port at a time, across processes too (duplicated 
or inherited handles included), so a listening socket shared by several 
processes can only be polled by one of them.
   
   - IOCTL_AFD_POLL on the AFD driver (\Device\Afd), what libuv (uv_poll), 
Rust's mio and wepoll use, through a completion port owned by the pollset: each 
socket has at most one poll request pending, completed once (cancelled with 
CancelIoEx(), or by closing the AFD handle, which completes everything pending 
at once), so there's no removal ordering issue, and the same socket can be in 
several pollsets. It passes all of testpoll, the race test above included, on 
both Windows 10 and Windows 11 (APR_POLLIN/OUT/PRI, APR_POLLONESHOT and 
APR_POLLRDHUP; no APR_POLLET, which for AFD would cost the same as a one-shot 
re-arm). The catch is that AFD is undocumented, though it has been stable for 
many Windows versions and the projects above rely on it.
   
   So I'd go with AFD for a scalable pollset on Windows. I just rebased and 
pushed my branch to https://github.com/ylavic/apr/tree/trunk-pollset-afd, if 
you want to look or try or take it; I'm also preparing numbers comparing 
select, WSAPoll, AFD, ProcessSocketNotifications() and this PR's method.
   
   What do you think?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to