Skip to main content

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.

  1. Start the Registry Editor.

  2. Browse to, and then select the following key in the registry:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

  3. 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>
  4. Save the changes and close the Registry Editor.

warning

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.

  1. Start the Registry Editor.

  2. Browse to, and then select the following key in the registry:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

  3. Create a new DWORD value, or modify the existing value of TcpTimedWaitDelay to alter the TIME_WAIT duration:

    • Value name: TcpTimedWaitDelay
    • Value data: <Enter a decimal value between 30 and 300 seconds>
  4. Save the changes and close the Registry Editor.

warning

You must restart your computer for this change to take effect.