Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket client buffering sent messages (Nagle's algorithm) #456

Open
ILikon opened this issue May 14, 2018 · 1 comment
Open

Websocket client buffering sent messages (Nagle's algorithm) #456

ILikon opened this issue May 14, 2018 · 1 comment

Comments

@ILikon
Copy link

ILikon commented May 14, 2018

Hello there,
I'm currently using this library to communicate with a microcontroler through websockets. The microcontroler acts as the server and my program on my PC as the client using this library.
I'm trying to send small messages (~10 chars) at every 10 ms, and I'm noticing that the messages are being buffered instead of sent right away.
To do this I made a small debugging program on the microcontroler that outputs the delay between consecutive messages after a batch of 100 messages, and I'm getting the following patterns:

...
msg[49]: 123601 us
msg[50]: 160 us
msg[51]: 145 us
msg[52]: 145 us
msg[53]: 145 us
msg[54]: 145 us
msg[55]: 145 us
msg[56]: 145 us
msg[57]: 144 us
msg[58]: 145 us
msg[59]: 145 us
msg[60]: 145 us
msg[61]: 184 us
msg[62]: 123145 us
msg[63]: 160 us
msg[64]: 145 us
msg[65]: 145 us
msg[66]: 145 us
msg[67]: 145 us
msg[68]: 145 us
msg[69]: 145 us
msg[70]: 145 us
msg[71]: 145 us
msg[72]: 145 us
msg[73]: 184 us
msg[74]: 123218 us
msg[75]: 160 us
msg[76]: 145 us
msg[77]: 145 us
...

To make sure the problem is not with the microcontroler, I coded a small javascript to act as the client and send the messages in a similar fashion. I used Firefox and the pattern I got is much more stable, as follows:

...
msg[63]: 12411 us
msg[64]: 11614 us
msg[65]: 12295 us
msg[66]: 12078 us
msg[67]: 14139 us
msg[68]: 9519 us
msg[69]: 12315 us
msg[70]: 11693 us
msg[71]: 12170 us
msg[72]: 11659 us
msg[73]: 12506 us
msg[74]: 11826 us
msg[75]: 12107 us
msg[76]: 12408 us
msg[77]: 11819 us
msg[78]: 11873 us
msg[79]: 11801 us
msg[80]: 11709 us
msg[81]: 12457 us
msg[82]: 11718 us
msg[83]: 14982 us
msg[84]: 10588 us
msg[85]: 10740 us
msg[86]: 12524 us
msg[87]: 13895 us
...

So this leads me to believe that the problem is happening in the client side.
A friend of mine told me that it could be related to Nagle's algorithm, which buffers TCP messages to avoid large overheads (https://en.wikipedia.org/wiki/Nagle%27s_algorithm).
It does match the symptoms. I've tried to look around for any option to disable this behavior but found nothing.
However I found this topic: #327
The author of the topic discusses this problem and commits a solution I believe.
Now, I'm new to GitHub (signed up just now), so I don't understand very well what happens. But it looks to me that those changes are not in the current master branch so I'm guessing they were not accepted.
Thus, can any one explain to me if there is any other way to disable this buffering behavior with the current implementation?
Or am I supposed to download and compile that branch in order to have access to that option?
What is the common procedure in this kind of situations?

Thanks for any answer you can provide.
Cheers

@VRRollerCoaster
Copy link

Did you ever find the solution to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants