4

I currently have an application that receives real time messages at a very high rate and my application needs to display those messages instantly. I read about nagles algorithm and I understand that it combines small messages into one big message and then transmits it (It is designed to reduce the number of acknowledgement packets by delaying the ACK for a short time).My question is will disabling Nagles algorithm help my application ? all my messages are to be displayed in realtime as soon as they are received.Any suggestions on this issue would be appreciated.

Update: Also I only have control of the receiver , will disabling nagles algo. on the receiver have any affect or does it only have affect when its disabled on the sender ?

MistyD
  • 16,373
  • 40
  • 138
  • 240
  • Nagle's algorithm applies exclusively to TCP packets. From the sound of it, you should probably be using UDP instead. Realistically, as far as instant display goes: Nagle's algorithm is generally irrelevant. Monitor updates happen at intervals on the order of tens of milliseconds (and human perception is mostly slower still). With that in mind, the time frames used by Nagle's algorithm is generally too short to matter. – Jerry Coffin Jun 23 '13 at 07:50
  • Your description is completely incorrect. The Nagle algorithm is designed to reduce the number of outgoing packets, by coalescing them if there is a current outgoing packet with an outstanding ACK. Delayed or selective ACK is a completely separate matter. Per your comment below, the Nagle algorithm affects sending, not receiving. Not a real question – user207421 Jun 23 '13 at 10:27
  • That is what I mean sending small messages (by disabling nagles algo.) across the network instead of waiting for a message to reach a certain size limit or after a certain delay.Although disabling would congest my network but would it improve application performance in my case ? – MistyD Jun 24 '13 at 04:47
  • It may be what you meant, but it isn't what you said. You're going to have to test and measure. – user207421 Jun 24 '13 at 10:55

1 Answers1

3

Nagle is a sender side algorithm only, so if you can only affect the receiver, you cannot disable it.

Even if you could affect the sender, disabling Nagle is not very effective when doing one directional communication. In bidirectional communication, disabling Nagle can improve throughput because the benefits of removing delays can accumulate as each node can send its responses slightly sooner, letting the other side respond even sooner than that. However, in the one direction case, disabling Nagle can decrease latency by one round trip, but those benefits cannot accumulate because the fact that you are not delaying packets does not slow down the generation of new packets. You never get ahead by more than one round trip. Over the internet, that's ~20-30ms. Over a LAN, that's usually ~1ms

If your system is sufficiently hard real time that a single round-trip latency matters, then TCP is a poor protocol, and you should be using UDP instead. Nagle is a TCP only algorithm, so it would not affect UDP.

Just for fun: Pinging a local computer on my LAN is <1ms. This means Nagle can only delay my messages by something under 1ms. Quantums for desktop computer schedulers can 20-60ms [1], and even longer for servers, so I would expect removing the nagle algorithm to have no visible effect on my LAN, dwarfed by the effect of other threads on my computer consuming the CPUs

[1] http://recoverymonkey.org/2007/08/17/processor-scheduling-and-quanta-in-windows-and-a-bit-about-unixlinux/

Cort Ammon
  • 10,221
  • 31
  • 45