A large number of solutions TIME_WAIT connections

1, a keep alive connection (to be added)

2, modifying the parameter tcp

The TCP connection is disconnected predetermined protocol, initiating one active socket closed, it will enter the socket TIME_WAIT state, TIME_WAIT state will last 2 MSL (Max Segment Lifetime), 4 min default in Windows, i.e. 240 seconds, the TIME_WAIT state the socket can not be recycled. Specific phenomenon is for a server handle a large number of short connections, if the server closes a client connection will result in the presence socket lot of TIME_WAIT state of the server-side, or even much more socket in the Established state than in seriously affected server processing power, or even run out of socket available, out of service. TIME_WAIT TCP protocol is being used to guarantee the socket will not be re-allocated remaining before the delay mechanism retransmission attempts text effects, it is necessary to ensure logic.

Resolution: found large TIME_WAIT state system is connected, it is solved by adjusting kernel parameters.

# vi /etc/sysctl.conf  //加入以下内容,net.ipv4.tcp_syncookies默认就有,不需要再添加
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1

# The TIME-WAIT sockets for new connections can be reused
net.ipv4.tcp_tw_reuse = 1

# Enable fast recycling of TIME-WAIT sockets status
net.ipv4.tcp_tw_recycle = 1

# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 30

  

Then execute / sbin / sysctl -p parameter lets take effect

/sbin/sysctl -p

  

Appendix 1.Linux Parameter Description
net.ipv4.tcp_syncookies = 1 indicates turning SYN Cookies, when the SYN queue overflow occurs, treatment can prevent cookies to be enabled small amount of SYN attack, default 0 means closed.
net.ipv4.tcp_tw_reuse = 1 indicates turning reuse TIME-WAIT sockets allow re-used for new TCP connection, the default is 0, it off.
net.ipv4.tcp_tw_recycle = 1 represents the fast recovery of the TCP connection open TIME-WAIT sockets, the default is 0, it off.
net.ipv4.tcp_fin_timeout = 30 TIMEOUT time modify the system default, to 30s.

TIME_WAIT wait for the next set time parameters described in Appendix 2.Windows
in HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Tcpip \ Parameters, add the named TcpTimedWaitDelay
DWORD key is set to 30, the shortest 30 seconds to shorten the waiting time the TIME_WAIT.

Guess you like

Origin www.cnblogs.com/itplay/p/11371651.html