Server (for example: HTTP) has a large number of time_ Solutions to wait

To understand TCP several state of the students, we should all know, TCP active disconnected side will appear TIME_WAIT state, TIME_WAIT state will keep the MSL 2 time, this is mainly used to prevent, take the initiative to open a party sent to the LAST lost a FIN ACK, lead to passive passive close one LAST – ACK timer timeout retransmission FIN, avoid the TCP state of chaos. However, in the case of high server concurrency, this default mechanism may cause the server to maintain a large amount of TIME_WAIT state, resulting in a large waste of resources, which may affect subsequent connection and request processing. To solve this phenomenon, we can modify the configuration of the server. Here we take the configuration of a Linux server on Aliyun as an example.
[root@izbp1dnvbin1s4fqqr8izfz ~]# cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.file-max = 1000000
net.core.somaxconn = 2048
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 16384
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_max_tw_buckets = 40000
vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
Net. Ipv4.com.lo. Arp_announce =2
net. Ipv4.com.conf.all. Arp_announce =2
net Net ipv4.tcp_fin_TIMEOUT (FIN timeout), net ipv4.tcp_TW_reuse (time_wait state socket reuse to allow socket to be used for a new TCP connection, default 0, Net ipv4.tcp_tw_recycle(fast recovery of time-wait sockets in TCP connections, default is 0, close), and then use the /sbin/ sysctL-p command to make the configuration work.

Read More: