TCP Messages Merged

centos6networkingtcptcpdump

I have an application that sends 100 of 186-byte (excluding headers) TCP messages back to back without gap from host A to host B.

I ran tcpdump to capture the packets on host A (where the sender is), and I noticed that after few messages (like 9), then the next ~25 messages got merged into one 5+K message.

I have already turned off Nagle's algorithm through setsockopt() in the sender application, and the calculated TCP windows is over 14K byte all the time. Hence, it doesn't seem like the first 9 messages filled up host B and host B asked host A to slow down.

Any tips on how to figure out why the TCP messages got merged?

Thanks!

Best Answer

I have an application that sends 100 of 186-byte (excluding headers) TCP messages back to back without gap from host A to host B.

Then you may be sending them faster than the network can transport them, in which case, by the time the TCP implementation on the sender is ready to send a packet on the network, there may be multiple messages queued up, in which case it'll send as many as it can in a single TCP segment. The TCP protocol offers a byte-stream service, with no notion of message boundaries, so it's permitted to do that.

I have already turned on Nagle's algorithm

Nagle's algorithm explicitly does what you're saying the TCP on the sender is doing:

Nagle's algorithm works by combining a number of small outgoing messages, and sending them all at once.

so turning it on won't prevent that. Turning it off might, in some cases, prevent that, but given that your application sends a burst of messages, it probably won't prevent that.

(I.e., the answer to "why did the TCP on the sender merge the messages?" is "because it can".)

Related Topic