Closed alexheretic closed 1 year ago
I've updated this PR to use the new tungstenite read
, write
, flush
API. And marked it as a draft since tungstenite 0.20
is not yet released.
If there is nothing that is broken, we can publish a new release right now. That is, after this work is finished :)
To be clear this PR is pretty much ready to go. It'll need an update to replace the dependency on tungstenite git is all.
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 + https://github.com/snapview/tungstenite-rs/pull/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 https://github.com/snapview/tungstenite-rs/pull/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).