FreeMemory
FreeMemory

Reputation: 8614

Unclear on Nagle's Algorithm

I've been doing some research on Nagle's algorithm out of idle curiousity. I understand the basic concept behind it (TCP packets contain a significant amount of overhead especially when dealing with small payloads), but I'm not sure I grok the implementation.

I was reading this article on Wikipedia, but I'm still unclear on how it works. Let's take the example of a Telnet connection. The connection is established and I begin typing. Let's say I type three characters (cat, for example) and hit return. Now we're talking cat\r\n which is still only 5 bytes. I'd think this would not get sent until we queue up enough bytes to send - and yet, it does get sent immediately (from a user perspective), since cat is immediately executed upon hitting return.

I think I have a fundamental misunderstanding here on how the algorithm works, specifically regarding the bit where "if there is unconfirmed data still in the pipe, enqueue, else send immediately."

Upvotes: 1

Views: 996

Answers (2)

Alexei Tenitski
Alexei Tenitski

Reputation: 9360

Read this post, it is quite in-depth and clarified a lot of the things for me.

Upvotes: 0

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171411

The data gets sent immediately only if the server has already responded to any previous messages from you (or this is your first contact with it in this session). So, as the server gets busier and slower to respond, in order to avoid swamping it with too many packets, the data gets queued up to a maximum packet size before getting sent.

So whether data gets sent immediately or not only can be determined in the context of previous messages, if any.

Upvotes: 5

Related Questions