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

Proposal: Add support for TCP_NODELAY option in libmosquitto #1526

Closed
fmoessbauer opened this issue Dec 10, 2019 · 3 comments
Closed

Proposal: Add support for TCP_NODELAY option in libmosquitto #1526

fmoessbauer opened this issue Dec 10, 2019 · 3 comments
Milestone

Comments

@fmoessbauer
Copy link

libmosquitto with QoS > 0 shows a very high latency when publishing. This is due to a high latency of messages send from publisher to the broker (~ 40ms).

The reason for the high latency is the TCP stack, because it waits for more incoming packets to group them together. This could be avoided by setting TCP_NODELAY for all sockets. For the mosquitto broker this can be done in the config file. The mosquitto client library has no API functionality to pass flags to the socket. However, the behavior of the Nagel algorithm has to be specified on sender side.

The following diff contains a proof-of-concept showing how to set the TCP_NODELAY flag in libmosquitto (using a compile time option). With this PoC, we were able to reduce the RTT from ~40ms to less than 1ms. For a production ready solution, this option should be selectable at runtime by using e.g. a further API call, or an additional parameter in mosquitto_connect or mosquitto_connect_bind

libmosquitto_nodelay.patch.txt

Xref: #433

ralight added a commit that referenced this issue Dec 18, 2019
Closes #1526. Thanks to Felix Moessbauer.
@ralight
Copy link
Contributor

ralight commented Dec 18, 2019

Will that do the job?

@fmoessbauer
Copy link
Author

@ralight: Thanks for taking care of this. I tested your patch and the results match perfectly with what I measured in the PoC.

Note for future readers: To enable the TCP_NODELAY flag: set

mosquitto_int_option(mosq, MOSQ_OPT_TCP_NODELAY, 1);

In a ping-pong test between two Raspberry Pis, I measure the following latencies:

# unpatched version
lat_circ[ms]:    88.00, lat_step[ms]:    44.00, msg/s:       24
# patched version
lat_circ[ms]:     2.06, lat_step[ms]:     1.03, msg/s:      972

What an improvement. Again: Thanks for your great work.

@ralight ralight added this to the 1.7 milestone Jan 30, 2020
@ralight
Copy link
Contributor

ralight commented Jan 30, 2020

I'm closing this, it will be part of 1.7.

@ralight ralight closed this as completed Jan 30, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 5, 2020
@ralight ralight modified the milestones: 1.7, 2.0 Oct 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants