1

I'm trying to understand the consequence of using Nagle's algorithm with different send buffer size values.

My current understanding of the send buffer is that it refers to a part of memory where a copy of the unacknowledged sent packet is stored. Once an ACK is received for the that packet, the send buffer is cleared. If an ACK is not received, the packet is sent again from the send buffer. Please correct me if I'm wrong.

Now my questions -

  1. If the send buffer is full, does that mean that no new packets will be sent to the receiver, even if Nagle's is disabled?
  2. What happens if I set the send buffer size to 0 and disable Nagle's? Do I just lose the ability to resend a lost packet in case an ACK never arrives?
user2635088
  • 1,598
  • 1
  • 24
  • 43
  • The send buffer is where data you send (with `send` or `write` or equivalent) is stored *before* it is transmitted. If the buffer is full then `send` (or equivalent) should block. Think of it more like an intermediate queue, data goes in at one end (from `send` etc.) and goes out the other (when the network stack transmits it). If it worked like you wonder in question 2, then the whole principle of TCP of being *reliable* would fall down. – Some programmer dude Nov 14 '16 at 13:12
  • Hmm so how does disabling Nagle's interact with SO_SNDBUF? Does it mean that disabling Nagle's algo will bypass the send buffer? If yes, will I save on memory by setting my `send buffer size` to 0 (with Nagle's algo disabled)? @Someprogrammerdude – user2635088 Nov 14 '16 at 13:23
  • Doesn't have to disable the buffer. It just means that the IP stack will send packets as soon as it can. With Nagle's enable, the network stack may wait a little time to see if there are multiple packets being queued in the send buffer so it can combine them into one larger transmission. With the algorithm disabled there's no timeout like that; If a packet is available to be sent then it is sent, doesn't matter how many packets are in the queue. – Some programmer dude Nov 14 '16 at 13:28
  • And setting the send buffer to zero might save memory, but can also cause all writes to block while the packet is being processed and transmitted successfully. *If* it's even possible to set the size to zero (OS dependent I think). Unless you are targeting a really small embedded system there's just no need to do it. – Some programmer dude Nov 14 '16 at 13:30
  • So whether or not Nagle's is enabled, the data is sent to the send buffer and we're not really getting any latency/memory advantage by setting the `send buffer size` to 0. – user2635088 Nov 14 '16 at 13:39
  • The impact on transmission rate should be negligible with a zero sized buffer. The impact on your programs flow might not be, especially if you send data in bursts. – Some programmer dude Nov 14 '16 at 13:45

0 Answers0