eclipse / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
8.64k stars 2.33k forks source link

Delayed ACK (40ms) and problems with splitted messages #1912

Open Den12321 opened 3 years ago

Den12321 commented 3 years ago

Hello, I have two problems with mosquitto. The first one is similar to the problem described in this thread (https://github.com/eclipse/mosquitto/issues/433) with the difference that I just want to send a few messages from my client to the broker every 250ms. I can send the first message immediately, but I have to wait around 40ms to send the second one. This happens because I use the nagle algorithm in the TCP/IP-Stack of my client which waits for the ACK of the first message. The problem is that the broker sends the ACK after 40ms instead of sending it as fast as possible. I tried to change this by setting set_TCP_NODELAY to true, but that didn’t fix my problem. I saw that TCP has an option called delayed_ACK. Is it possible that the broker uses the delayed ACK and how can i deactivate it? Can somebody tell me how to make the broker to ACK as fast as possible? I know that i could solve the problem by turning off the nagle algorithm at my client, but i don't want to do that. The following screenshot shows the communication with the delayed ACK's. image

The second problem appears if I send a few mqtt-messages and one of the messages gets split by the nagle algorithm. It looks like the broker(mosquitto) isn’t able to reassamble the message and resets the connection instead of it. Did somebody else has this problem?

ralight commented 3 years ago

Could you tell me what version you are using please?

Den12321 commented 3 years ago

Sure, i am using mosquitto 1.6.12a.

ralight commented 3 years ago

It's possible this is a bug with no delay not getting set on Windows only.

In terms of messages being split and not being reassembled - I've not seen anything like that myself.

Den12321 commented 3 years ago

Okay, thank you for your help.

The problem with the splitted messages not beeing reassembled only appears if i send more than 2 messages (i tried 3-10 messages) with a payload that's smaller than the MSS.

For example if i send 3 messages with a payload of 1458 Byte (MSS is 1560 Byte in my case) the first messages will be send directly with exactly 1458 Byte, the second message will be filled with the first 2 Bytes of the third message, so that the segment is filled up and the last message is decreased to 1456 Byte. It looks like the split of the third message can't be reassembled and the broker resets the tcp connection instead. If i send a message that is larger then the MSS the split and reassembly of the messages works fine.

ralight commented 3 years ago

Thanks for the details, I'll give that a try. The broker and clients have no concept of TCP packets, they just read data as it becomes available and don't expect a whole MQTT message at once. Very odd.