TIME_WAIT is an incredible part of the TCP/IP stack that enables connections to linger until the client properly closes the connection. However, in some cases, the client does not close the connection properly or efficiently. This can result in TCP connections in the TIME_WAIT state to persist until the operating system purges them. For a busy system, this can result in a denial of service on the host because all available connections get tied up in the TIME_WAIT state.
Having worked with many large-scale and high-performance systems through the years, I've seen this scenario play out many times. Fortunately, each operating system has its own way of optimizing for this scenario to minimize the impact.
To determine if this is a problem on your host, track the number of connections in the TIME_WAIT state. For example, on UNIX/Linux and MacOS systems, you can count these connections with netstat:
$ netstat -an|grep -c TIME_WAIT
Here are TCP tunings per operating system that I have used to mitigate this issue:
RedHat/Oracle Linux 8: /etc/sysctl.conf
RedHat/Oracle Linux 7: /etc/sysctl.conf
ndd -set /dev/tcp tcp_time_wait_interval 30000
Reduce TcpTimedWaitDelay from the default of 2 minutes (120 seconds) down to around 20 seconds
—> TcpTimedWaitDelay": dword:00000028
—> StrictTimeWaitSeqCheck: dword:00000001
Notes for Windows:
· Changing these values requires a reboot. Plan to do that out of your production hours.
· TcpTimedWaitDelay is 2 minutes by default, even if the value is not present in the registry.
· You must set the StrictTimeWaitSeqCheck to 0x1 or the TcpTimedWaitDelay value will have no effect.
While changing this parameter the following important points needs to be considered:
Changing these values requires a reboot. Plan to do that out of your production hours.
TcpTimedWaitDelay is 2 minutes by default, even if the value is not present in the registry.
You must set the StrictTimeWaitSeqCheck to 0x1 or the TcpTimedWaitDelay value will have no effect.
TcpTimedWaitDelay - https://technet.microsoft.com/en-us/library/cc938217.aspx