Time-Wait
Quick Recovery of sockets
Source http://www.xymyeah.com/494.html
I found a large number of time-Wait connections on my server, which can reach tens of thousands. By modifying kernel parameters, the system can quickly reclaim time-Wait sockets.
View TCP connections:
[Root @ centos ~] # Netstat-N | awk '/^ TCP/{++ s [$ NF]} end {for (a in S) print a, s [a]}'
Last_ack 56
Syn_recv 77
Established 11213
Fin_wait1 4013
Fin_wait2 1638
Closing 3
Time_wait 12261
Modify kernel parameters to quickly recycle time_wait sockets:
[Root @ centos ~] # Echo "net. ipv4.tcp _ tw_reuse = 1">/etc/sysctl. conf
# Indicates enabling reuse. Allow time-Wait sockets to be re-used for a New TCP connection. The default value is 0, indicating that the TCP connection is disabled;
[Root @ centos ~] # Echo "net. ipv4.tcp _ tw_recycle = 1">/etc/sysctl. conf
# Indicates to enable quick time-Wait sockets recovery in TCP connections. The default value is 0, indicating to disable time-Wait sockets.
[Root @ centos ~] # Sysctl-P
After the modification is complete, check the TCP connection status. The time-Wait connection is significantly reduced, and it seems that Apache access is much faster.
[Root @ centos ~] # Netstat-N | awk '/^ TCP/{++ s [$ NF]} end {for (a in S) print a, s [a]}'
Last_ack 26
Syn_recv 225
Established 9228
Fin_wait1 4002
Fin_wait2 611
Closing 2
Time_wait 415 http://www.xymyeah.com/494.html more