My IIS 5.0 server is usually under a large load, and performance slows periodically. While investigating the problem, I've discovered more than 1000 TCP ports in the TIME_WAIT state. Is this state typical on an active server, and could it be affecting performance?

The TIME_WAIT state is typical, but it can also affect performance. You might want to adjust the amount of time your IIS machine keeps a TCP/IP session open after the client has disconnected. After a connection is closed, the server port goes into a TIME_WAIT state when the client sends the server a FIN packet. By default, the server then keeps the connection alive for 4 minutes. (Internet Engineering Task Force—IETF—Request for Comments—RFC—793 provides the rationale for keeping the connection alive this long.) As long as the server port is in TIME_ WAIT state, no other connections can be made to the port. This default time is protection against delayed network communication from an old session intermingling with communication from a new session and resulting in unpredictable consequences.

Network traffic on today's Internet and intranets is unlikely to have a 4-minute latency. Consequently, you can usually decrease the TIME_WAIT interval to 1 minute or less. This change will cause your server to recycle connections almost four times faster than the default configuration, resulting in more efficient use of your server's resources. You can use the Netstat (netstat.exe) utility to determine how many ports are in the TIME_WAIT state. (For more information about TCP connections and the Netstat utility, see the Microsoft article "TCP Connection States and Netstat Output" at http://support.microsoft.com/support/kb/articles/q137/9/84.asp.)

The setting you need to adjust to change the TIME_WAIT interval doesn't exist by default. You must add the Tcp TimedWaitDelay REG_DWORD value to the HKEY_LOCAL_MACHINE\ SYSTEM\CurrentControlSet\Services\ Tcpip\Parameters registry subkey. Then, you set the delay to the number of seconds (in decimal form):

Value Type: REG_DWORD--
  Time in seconds
Valid Range: 30­300 (decimal)
Default: 0xF0 (240 decimal)

Of course, before you make any changes to the registry, be sure you have a good recovery system in place. For more information about this registry change, see the Microsoft article "TCP/IP and NBT Configuration Parameters for Windows" (http://support.microsoft.com/support/kb/articles/q120/6/42.asp) and the Windows Registry Guide Web site (http://www.winguides.com/registry/display.php/878).

Another factor that can affect performance is that you might be running low on ephemeral ports—ports used to create connections to the client computers from the server and between COM server objects. By default, these ports range from 1024 to 5000, and if you run out of them, connection problems can occur. As the Microsoft article "Unable to Connect from TCP Ports Above 5000" (http://support.microsoft.com/support/kb/articles/q196/2/71.asp) states, you can increase the number of ports available to 65,535. Each port uses 2KB to 4KB of memory, so be certain you have ample RAM to support the number of connections you intend to use. (Each connection requires at least one port.)