[200 OK]: A Port80 Software Blog

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

Hurry Up and TIME_WAIT, part II

Several posts back I explained the curious phenomenon of the majority of TCP connections on busy Web servers being in the TIME_WAIT state, due to the peculiar way TCP has of closing connections (namely, via a full duplex handshake).  Alert readers will have noticed that the explanation was incomplete.  It never said anything about why it is that Web servers, in particular, that experience this problem (and not, say, database servers, file servers, or what have you).

Really alert readers will also have figured out the answer by now:  Web servers, not Web clients, tend to initiate the connection close.  The example I used to describe the full duplex handshake assumed this.  But if you actually go look this stuff up in the TCP spec or a good reference, you will that the server and client roles are reversed.  TCP tends to assume that it will be the client initiating the close, not the server.

And when that is the case, the TIME_WAITs don't accumulate the way they do on a busy Web server.  Since the client has the active close, it's the client that winds up in the TIME_WAIT.  The burden of keeping old and new data from intermixing is dispersed among cilents, instead of being concentrated on servers.

All of which in turn points to the odd fact that HTTP actually uses TCP in ways that are not entirely consonant with the what the creators of the latter envisioned.  TCP has been well-described as a connection-oriented protocol layered over a connectionless one (IP).  With HTTP, we get a stateless protocol layered over one that inherently maintains states (such as TIME_WAIT), even while tearing down a connection.

When you think about it like that, it's quite astonishing that all this works as well as it does!

posted on Monday, December 13, 2004 5:33 PM

Feedback

# re: Hurry Up and TIME_WAIT, part II

Thanks for all the good information!

I've been looking at a few IIS servers that are currently exhibiting the TIME_WAIT behavior that you describe. In addition to the 2MSL timeout, HTTP keep-alives and the corresponding connection timeout seem to have a bearing on the duration of TIME_WAIT. The particular servers I'm looking at have a very long connection timeout setting, so I am trying to minimize the number of TIME_WAIT connections. That said, I'm having difficulty replicating TIME_WAIT connections. The only way I've been able to make it happen thus far is to disable keep-alives in IIS.

Can you elaborate on the role of HTTP keep-alives in the TIME_WAIT scenario? Thanks.
12/16/2004 6:27 PM | Ryan

# This is no time to argue about time -- we haven't got the time.

4/3/2006 12:17 PM | [200 OK]: A Port80 Software Blog

# This is no time to argue about time -- we haven't got the time.

8/16/2006 3:01 PM | [200 OK]: A Port80 Software Blog

# re: Hurry Up and TIME_WAIT, part II

thanks nice text
4/7/2008 7:56 AM | software

Post Comment

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