Overcoming TCP/IP Connection Limits
If you are using a high number of TCP connections, particularly with a high connect/disconnect rate, you may exhaust the number of available ports as they may all be in the TIME_WAIT
state.
There are two actions that can prevent this:
- Increasing the number of available (ephemeral) ports.
- Reducing the
TIME_WAIT
timeout period.
Increasing the Number of Available (Ephemeral) Ports
By default Windows only allocates ephemeral ports in the range 1024 through 4999.
To increase the upper range of ephemeral ports that are dynamically allocated to client TCP/IP socket connections perform the following. You should first save a backup of the registry.
-
Start the Registry Editor.
-
Browse to, and then select the following key in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
-
Create a new DWORD value, or modify the existing value of
MaxUserPort
to increase the number of ephemeral ports that can by dynamically allocated to clients:- Value name:
MaxUserPort
- Value data:
<Enter a decimal value between 5000 and 65534>
- Value name:
-
Save the changes and close the Registry Editor.
You must restart your computer for this change to take effect.
Reducing the TIME_WAIT
Timeout Period
This setting determines the length of time that a connection will stay in the TIME_WAIT
state before being closed. The default is 240 seconds which on a busy server will limit the maximum connections to around 200/sec. Reducing this setting will increase the maximum connection limit.
-
Start the Registry Editor.
-
Browse to, and then select the following key in the registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
-
Create a new DWORD value, or modify the existing value of
TcpTimedWaitDelay
to alter theTIME_WAIT
duration:- Value name:
TcpTimedWaitDelay
- Value data:
<Enter a decimal value between 30 and 300 seconds>
- Value name:
-
Save the changes and close the Registry Editor.
You must restart your computer for this change to take effect.