I am using webSockets to connect a javascript webSocket client to a java webSocketServer (from an Android application), using the Java-WebSocket library. The Android app sends a small message every few milliseconds to the javascript client.
Using the basic (and intuitive) approach for this situation, the delay between received messages, measured inside the javascript Client show (aproximately) the following pattern: 200 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 200 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 200 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms, 0.1 ms ...
This is the effect of the Nagle algorithm, that is set by default, clumping several messages before sending them.
Since I have not found a way to guarantee its deactivation, I follow the approach proposed in this old question, sending an acknowledge message from the client to the server, and the system behaves properly, but since the acknowledge message has no real purpose (it is more a hack), it should be avoided.
The question is, this keeps being the best solution to this problem? Do you know any way to avoid the clumping?
Thank you.
To disable Nagle's buffering algorithm, use the TCP_NODELAY socket option. To disable Delayed ACKs, use the TCP_QUICKACK socket option. Enabling the TCP_NODELAY option turns Nagle's algorithm off.
Nagle's algorithm is a TCP optimization that makes the stack wait until all data is acknowledged on a connection before sending more data. This process, called "nagling", increases the efficiency of a network application system by decreasing the number of packets that must be sent.
The most direct way would be to trace the setsockopt system call. Looking from the outside you can only notice when it disables Nagle and behaves bad (sends lots of small fragments rapidly). If it disables Nagle and behaves well, you cannot notice from outside.
Since no flush or setTCPNoDelay mechanisms seem to be present on the used library, and no other solutions have been proposed, it seems that the acknowledge message solution remains valid as the best solution to this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With