deniszykov / WebSocketListener

A lightweight and highly scalable asynchronous WebSocket listener
http://vtortola.github.io/WebSocketListener
81 stars 17 forks source link

[Question] - Continuation frame == Nagle? #54

Closed tcounts closed 4 years ago

tcounts commented 4 years ago

The WebSocket library appears to follow every initial data frame with a slightly-delayed (~40ms) empty continuation frame that has the Final bit set. We think this is related to the Nagle Algorithm being enabled.

The original vtortola implementation had an option to turn this off, but it has been removed this in your fork.

1) Is the continuation frame from the Nagle algorithm? 2) Is there a way to turn this off in this fork?

deniszykov commented 4 years ago

Hi @tcounts! All socket options are set via TcpTransport properties. One of them is TcpTransport.NoDelay which sets Socket.NoDelay. You can configure TCP options with following code:

WebSocketListenerOptions.Transports.ConfigureTcp(tcp =>
{
    tcp.BacklogSize = 100; // max pending connections waiting to be accepted
    tcp.NoDelay = true;
    tcp.ReceiveBufferSize = bufferSize;
    tcp.SendBufferSize = bufferSize;
});
tcounts commented 4 years ago

Thanks. I set the NoDelay, and that did not make a difference on what we were seeing, so Nagle does not appear to be the issue. Basically - we ALWAYS get the continuation frame packet even if the message is small enough to fit into a sing;e message.

deniszykov commented 4 years ago

If you want to write small message as single frame you could use WebSocketMessageWriteStream.WriteAndCloseAsync method. Other approaches send at least 2 frames.

tcounts commented 4 years ago

Thanks. I switched over to WebSocketMessageWriteStream.WriteAndCloseAsync.