Honour a de-armed READABLE in read_more; drop the fcntl pair after SOCK_NONBLOCK - #257
Open
jimmyolo wants to merge 2 commits into
Open
Honour a de-armed READABLE in read_more; drop the fcntl pair after SOCK_NONBLOCK#257jimmyolo wants to merge 2 commits into
jimmyolo wants to merge 2 commits into
Conversation
read_more re-reads whenever one recv filled the buffer, so that a hangup queued in the same iteration cannot close the socket before the data is drained. That is still done here. What changes: if on_data de-armed LIBUS_SOCKET_READABLE (us_poll_change from inside the callback, which is how a consumer says "stop"), the loop now honours it instead of reading until close. Before, a paused consumer kept receiving 512 KB per pass while the peer's window stayed open; measured 2.8 MB queued against a 64 KB mark on a pulsed-drain peer.
bsd_create_socket and bsd_accept_socket already pass SOCK_NONBLOCK where the platform has it, then call bsd_set_nonblocking anyway: F_GETFL plus F_SETFL on a descriptor that is already non-blocking. Four fcntl per connect+close (client and accepted socket) that do nothing, 4.00 to 0.00 under strace -c. The #else keeps the fcntl pair for platforms without the flag.
Contributor
|
what kind of perf. do you see with your net.Socket, net.Server kind of reimplementation vs. Node.js's own? |
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 small fixes found while building a Node.js
netimplementation on uSockets (epoll backend, upstream pinned at2353808).1.
loop.c: stopread_moreonce the poll mask no longer hasREADABLEThe re-read after a full 512 KB
recvis kept — the comment's reason (a hangup queued in the same iteration closing the socket before the data is drained) still holds. The change is one extra condition: ifon_datade-armedLIBUS_SOCKET_READABLEviaus_poll_change, which is how a consumer says "stop reading", the loop honours it instead of reading until close.Before this, a consumer that paused from inside
on_datakept receiving 512 KB per pass for as long as the peer's window stayed open. Reproduction: a peer that drains in pulses against a 64 KB high-water mark queued 2.8 MB (Node's ownnetpeaks at 124,928 bytes on the same peer); after the guard the peak is exactly oneLIBUS_RECV_BUFFER_LENGTH. A peer that never reads does not show it, since the window closes — which is why it hid.AsyncSocket.h:57in uWebSockets de-armsREADABLEthe same way, so it should benefit too.2.
bsd.c: skipbsd_set_nonblockingon sockets created withSOCK_NONBLOCKbsd_create_socketandbsd_accept_socketalready passSOCK_CLOEXEC | SOCK_NONBLOCKwhere the platform defines them, and then callbsd_set_nonblockinganyway:F_GETFL+F_SETFLon a descriptor that is already non-blocking. That is fourfcntlper connect+close (client socket plus accepted socket) that do nothing. Understrace -c, 4.00 → 0.00 per connection. The#elsebranch keeps the fcntl pair for platforms without the flag, under the same#ifthat adds it, so the two cannot disagree.Both changes are being carried as build-time patches downstream (https://github.com/jimmyolo/u-socket/issues/140); happy to split them into two PRs if preferred.