[200 OK]: A Port80 Software Blog

We're all 200 OK: Web, HTTP and IIS Insights
posts - 199, comments - 719, trackbacks - 95

TCP_NODELAY: To Nagle or Not To Nagle?

An interesting question came up recently when someone asked if we knew of a way to disable the Nagle algorithm for IIS. 

Well, it used to be possible to disable it for applications using the MSMQ (Microsoft Message Queue Server).  The magic registry key is documented here (look under “Disabling the Nagling Option“).  And of course if you write your own Windows socket application you can disable the Nagle algorithm by setting the TCP_NODELAY socket option, as mentioned here (though as you can see, Microsoft discourage the practice).

But I'll be darned if we haven't failed to find the link that says whether and how this can be done in Windows 2003 (and hence for IIS 6.0).

Why are we even bringing this up?  What the heck is a Nagle?

Actually, it's who.  John Nagle is the author of the algorithm that bears his name and its something that's been a part of TCP for years.  It even has it's own RFC -- RFC896 called, significantly, Congestion Control in IP/TCP Networks.  Check out the “backwards” spelling of TCP/IP -- that's how old this thing is.

John Nagle worked for Ford Aerospace and, to make a long story short, they had a lot of congestion on their network due to lots of tiny packets (think telnet).  Nagle's brilliant solution was the Nagle algorithm which says, essentially, only send one small packet out without getting an acknowledgment (ACK).  Otherwise, wait until you've got enough of them to send out a full-sized packet (or segment, if you want to get technical).

This works great, except for one thing -- it can interact badly with another TCP performance optimization called Delayed ACKs.  Delayed ACKs are ACKs that wait around looking for data-bearing segments to piggy back on, the idea being that it's more efficient to send the ACK together with the next bit of real data, instead of wasting time sending it all by its lonesome.

Problem: Imagine a Web server sending one full segment plus a bit more.  Maybe someone tried to optimize their homepage a la Google, but didn't quite fit it all into one packet.  The first segment goes out okay, but then the Nagle algorithm requires that the server wait for that ACK before sending the next piece, because it's undersized.  Meanwhile, on the client, the ACK that would free up the server to do its thing is being held back, waiting for more data bound for the server, so it can piggy back on that data.

Ta-da!  Deadlock.  It's temporary, of course, because the delayed ACKs have a timeout, after which they just get sent anyway.  And that, by the way, is an indirect way to disable one bad effect of the Nagle algorithm -- namely, by shortening the Delayed ACK timeout (or killing the delay altogether).  Find out how here.

 

posted on Monday, January 31, 2005 8:24 PM

Feedback

# re: TCP_NODELAY: To Nagle or Not To Nagle?

Nagle's original algorithm, devised for Telnet, as I read it did not send the first packet immediately, but rather always delayed for more data. The improvement suggested in RFC 896, to send the first packet of data immediately, and delay subsequent data, was an elegant compromise providing for the needs of a responsive send/response (client/server) connection and those of a packet minimizing streaming connection, with the transport layer automatically switching between conversation and streaming modes without advice of the sender. So Nagle gets the credit for this mostly satisfactory RFC896 implementation.

The problems come when a server either fragments it's data responses to the network, or has multiple things to say in response to a situation (a dubious distinction, to be sure, but a distinction of scope, that let's say the former should be solvable). I have stumbled upon an elegant interface to the Nagle algorithm that is almost always implemented in a TCP/IP connection, (and which is deserving of elegant treatment), and a Server. The trick is to explicitly disable Nagling (TCP_NODELAY) on the Server any time an explicit response to a request is to be sent. This will enable the response to be sent immediately (as well as any other queued data). Any time no-reply data is sent, Nagling is re-enabled. Thus, non-responsive informative messages will be blocked up and efficiently sent in MTU-s. These kinds of messages include state and data changes on the server, as well as progress indicator updates. The 200 msec delays is not devastating in these cases, and in any case the messages are always delivered in order.

So you can have the best of both worlds, even without a Mac.
5/9/2005 1:16 AM | shkeyser@nualumni.com

# re: TCP_NODELAY: To Nagle or Not To Nagle?

There seems to be some confusion as to when to use an apostrphe in the word its/it's. "its" is the genitive of it, as in: "The whole consists of the sum of its parts". "it's" = "it is" or "it has" - it's a contraction.
3/5/2007 1:12 PM | Dick Head

# re: TCP_NODELAY: To Nagle or Not To Nagle?

http://www.funingame.com
3/22/2008 3:58 AM | wow gold

# re: TCP_NODELAY: To Nagle or Not To Nagle?

thanks nice text.,
4/7/2008 7:38 AM | software

# SEX SHOP

SEKS SHOP
5/8/2008 8:29 AM | EROTİK SHOP

# SEKS SHOP

SEKS SHOP
5/8/2008 8:30 AM | SEKS SHOP

# SEX SHOP

SEKS SHOP
5/8/2008 8:30 AM | SEX SHOP

# EROTİK MARKET

SEKS SHOP
5/8/2008 8:32 AM | EROTİK MARKET

# EROTİC SHOP

SEKSSHOP
5/8/2008 8:32 AM | EROTİC SHOP

Post Comment

Title:  
Name:  
Url:  
Comment:  
Verify:
(Enter the word as it appears in the box above.)