Repository navigation
net: Windows writes through IOCP, broadcast receivers per listener (net engine N1 follow-ups) - #1394
Merged
Merged
Conversation
…et engine N1 follow-ups) Windows writes. A write that finds the socket full waited for room with async_wait(wait_write), which Asio implements on Windows with a select() thread beside IOCP. There, the rest of the output now goes as an overlapped async_write_some of the gathered buffers; the connection keeps their payloads until the handler runs, since a close clears the queue first. The first write is still a non-blocking write_some. -DCVC_NET_ASYNC_WRITES=1 takes the same path on other systems, to test it. Windows reads need no change: Asio's async_wait(wait_read) on a stream socket is a zero-byte overlapped WSARecv, so it already goes through IOCP and an idle connection still holds no read buffer. The fan-out benchmark's Windows default goes from 1000 receivers to 6000, the same as elsewhere. Counters. Each listener's block now counts broadcast_receivers: the receivers a broadcast reached through that listener's connections. broadcasts stays the engine's only, as the header now says. New test: NetEngine.EachListenerCountsItsOwnBroadcastReceivers.
transfix
force-pushed
the
feat/net-engine-n1-followups
branch
from
November 21, 2026 11:07
a5659ae to
3e6327a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two follow-ups to the connection engine's C++ core, N1 (#1392). See docs/roadmap/ARIADNE_NET_ENGINE.md.
Rebased onto master after #1392 merged (squash 35f5575): one commit, three files.
1. Windows: writes through IOCP. Reads needed no change.
Reads. #1392 listed a Windows read path as a follow-up. The reason given was that Asio implements
async_waitwith aselect()reactor thread on Windows. That is true forwait_writebut not forwait_read. In Asio 1.32 (detail/win_iocp_socket_service_base.hpp,async_wait),wait_readon a stream socket callsstart_null_buffers_receive_op. That function issues a zero-byte overlappedWSARecv, which is the usual way to wait for input on IOCP. So N1's reads already go through IOCP, and an idle connection still holds no read buffer.An
async_read_someinto a buffer per connection would give up that property and gain nothing, so reads are unchanged. A comment atstart_readand the file's header now say why.Writes.
wait_write(andwait_error) do use the select() reactor (start_reactor_op(impl, select_reactor::write_op, ...)). So on Windows, a write that finds the socket full now sends the rest as an overlappedasync_write_someof the gathered buffers:write_some, so a socket with room costs no completion.in_flight) until the handler runs, because a close clears the output queue before that.wrote(n), thenwrite_now(). Closing, flushing closes, lingering andwant_writablebehave as before.linger()still runs only once no write is in flight.-DCVC_NET_ASYNC_WRITES=1takes the same path on Linux and macOS, so it can be tested off Windows (see Tests).Fan-out default. The benchmark's Windows default N goes from 1000 to 6000, the same as elsewhere. On this PR's first CI run (before the rebase),
recipe / windows-2022 / Releaseran it at 6000 and passed in 8.8 s under a parallel ctest. All 24 NetEngine cases passed there.2. Broadcast receivers per listener
worker::apply's broadcast walk now bumpsconn->lst.broadcast_receiversfor each receiver, so each listener's block counts the receivers it gave.broadcastsstays the engine's only: one broadcast's receivers can come from several listeners. The header now says so (a listener's block reads 0).New test:
NetEngine.EachListenerCountsItsOwnBroadcastReceivers. One group has two connections from listener "hub" and one from "admin". It sends two broadcasts, one of them excluding a hub connection. Expected per listener:broadcast_receivers: hub 3, admin 2;messages_out: 3 and 2;broadcasts: 0 on each listener, 2 on the engine.Tests (prettyhatemachine, gcc 13)
ctest -R NetEngine: 24/24 (N1's 23 plus the new one).-DCVC_NET_ASYNC_WRITES=1, -O2 standalone): 24/24. Under gdb, its handler ran in the backpressure and close tests. The fan-out run at 6000 receivers measured 18.2 µs per receiver, against 17.6 µs on net: the connection engine's C++ core (ARIADNE_NET_ENGINE N1) #1392.-fsanitize=threadstandalone, three runs each of the default build and the forced-on build: 24/24 every time, no reports. These runs usedsetarch -R, because this kernel's ASLR entropy makes TSan abort at startup otherwise.Windows itself is untested locally; the Windows CI jobs are the check. Both macOS failures on the first CI run were the fan-out's "Too many open files" at connection 5114. That came from a pre-rebase base: #1392 fixed it later with a macOS descriptor ceiling, and the rebase brings that fix in.
Do not merge without Joe's OK.