websocket: fix write back-pressure #618
Merged
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.
Websocket transport is eagerly writing to underlaying websocket
without respecting back-pressure.
When an event is emitted to multiple clients, socket.io adapter
sends the same packet object to all socket clients.
These packet objects are shared for all clients inside room.
Once the packet is sent to transport,
transport prepares buffer with transport headers and packet data
and the sharing among clients is lost.
This change significantly reduces memory usage when
many packets are emitted to many clients in a burst.
This change causes that buffered data is sent to clients
more evenly packet by packet.
This change slightly (up to 10%) improved write throughput in the tests where
many packets are emitted to many clients in a burst.
The kind of change this PR does introduce
Current behaviour
Websocket transport does not respect back pressure from underlaying websocket
New behaviour
Websocket transport respects back pressure from underlaying websocket
Other information (e.g. related issues)