Remove flush on each WebSocketStream::poll_ready call + update to tungstenite 0.20 #284
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.
My context: I've been working on a websocket load generator service that will write lots of small json message events to it's ws clients. I was interested in having a high peak throughput from this service to allow me to test downstream load performance. It uses axum->tokio-tungstenite->tungstenite. Doing localhost testing I got ~1.2M msg/s peak throughput. This PR + snapview/tungstenite-rs#357 improves that to ~2M msg/s.
Currently each
SinkExt::feed
call will call into tungstenitewrite_pending
onpoll_ready
meaning flushing before each message write. This is a poor fit for sending lots of small messages where it would be better to be able tofeed
many messages thenflush
.From
poll_ready
docs:As tungstenite websockets have a write buffer I believe they are always ready to receive data, and so the impl in this PR simply always returns ready here (without flushing).
Note: Without snapview/tungstenite-rs#357 it actually makes little difference to performance since upstream was also eagerly flushing before each write. So this isn't a big win on it's own. However, if we can agree this impl is more correct I don't see any harm merging before changes upstream.
Update
Now updated to use tungstenite
0.20
(not yet released).