Best way to avoid Nagle algorithm effects with webSockets?

I use webSockets to connect the javascript webSocket client to java webSocketServer (from an Android application) using the Java-WebSocket library. An Android application sends a small message every few milliseconds to the javascript client.

Using a basic (and intuitive) approach for this situation, the delay between received messages, measured inside the javascript Client, shows (approximately) 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 default effect of the Nagle algorithm, discarding multiple messages before sending them.

Since I did not find a way to guarantee its deactivation, I follow the suggestion in

+5
source share
1 answer

Since flush or setTCPNoDelay mechanisms are not present in the library used, and no other solutions were proposed, it seems that the solution to the confirmation message remains valid as the best solution to this problem.

0
source

Source: https://habr.com/ru/post/1204734/


All Articles