bytebeamio / rumqtt

The MQTT ecosystem in rust
Apache License 2.0
1.59k stars 247 forks source link

Option to configure TCP no_delay #872

Closed FedorSmirnov89 closed 4 months ago

FedorSmirnov89 commented 4 months ago

Type of change

Description

This pull request adds an option to set the nodelay flag for the TCP connection in the MQTT client. The nodelay flag, when enabled, disables Nagle's algorithm, which can help reduce latency by sending packets immediately without waiting for a full buffer. This is particularly useful in scenarios where low latency is critical.

Changes

Issue

Checklist:

coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 9258539470

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
rumqttc/src/lib.rs 1 4 25.0%
<!-- Total: 2 5 40.0% -->
Files with Coverage Reduction New Missed Lines %
rumqttc/src/eventloop.rs 1 83.91%
<!-- Total: 1 -->
Totals Coverage Status
Change from base Build 9193063302: 0.001%
Covered Lines: 5977
Relevant Lines: 16541

šŸ’› - Coveralls
de-sh commented 4 months ago

have you tried comparing the actual performance difference with & without this flag? because if latency is bottle-necked by eventloop or some other thing, this might not be that boost right? please correct me if wrong

I believe OP is trying to use rumqttc in time critical applications where the messages they are trying to send aren't enough for nagling to be the right approach. We can safely provide this as an opt-in.

de-sh commented 4 months ago

Congrats on the merge @FedorSmirnov89 šŸŽŠ

FedorSmirnov89 commented 4 months ago

Thank you for merging :) . Just to add the information @swanandx was asking about: It's exactly as @de-sh said: We have a distributed application where two clients on different nodes exchange messages. We measured the timing of the messages since we want them to have as little latency and jitter as possible. They are exchanging very small messages on a high frequency (range of 1-4 ms).

Seeing that configuring the broker (we are using the normal Mosquitto which comes with an apt-get in Linux) to set no-delay for the messages it is sending significantly reduced the jitter, we did the same thing on the client side by building our agents of a local branch of rumqttc where we had the no-delay option enabled. Again, we saw a significant decrease in message jitter.

Thanks a lot for reviewing and merging :) . We can now go back again to building off the main branch of the repository which is great šŸ˜„