snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

How do I get current length of send buffer? #293

Closed vi closed 1 year ago

vi commented 1 year ago

How do I know which percentage of max_write_buffer_size's capacity is currently being used?

This may be needed to implement message priorities, so that more important messages get delivered even when less important messages are dropped / delayed when the buffer is half full.

Workaround: use small max_write_buffer_size and use additional in-app queue for outgoing messages. But small max_write_buffer_size may negatively affect performance when there is a lot of important messages.

Ideally it should be somehow available on futures::stream::SplitSink<tokio_tungstenite::WebSocketStream>.

daniel-abramov commented 1 year ago

Currently, there is no way to get access to such low-level data in a library (so far we have not thought of exposing one). I'm not sure that it would be very useful though, I feel like implementing a backpressure based on the volatile size of the internal buffer isn't the most optimal way to go.