MySQL server discovers a number of time_wait solutions

Source: Internet
Author: User

Find a lot of time_wait solutions


Netstat-an |grep time_wait |WC

1114 6685 99098


... ...

according to the TCP protocol defined by the 3-time handshake disconnection rules, initiates the socket active shutdown of the socket will enter the TIME_WAIT state, the TIME_WAIT state will continue 2 MSL (Max Segment Lifetime), Under Windows, the default is 4 minutes, or 240 seconds, and the socket in the TIME_WAIT state cannot be recycled. The specific phenomenon is for a server processing a large number of short connections, if the server actively shut down the client connection, will result in a large number of servers in the TIME_WAIT state of the socket, or even more than the socket in the established state, Severely affects the processing power of the server and even exhausts the available sockets to stop the service. Time_wait is a logical guarantee that the TCP protocol is used to ensure that a reassigned socket is not affected by a previously lingering delay redistribution.

Log in to the Web server (Linux):

Netstat-ae |grep MySQL

TCP 0 0 aaaa:53045 192.168.12.13:mysql time_wait root 0
TCP 0 0 aaaa:53044 192.168.12.13:mysql time_wait root 0
TCP 0 0 aaaa:53051 192.168.12.13:mysql time_wait root 0
TCP 0 0 aaaa:53050 192.168.12.13:mysql time_wait root 0
TCP 0 0 aaaa:53049 192.168.12.13:mysql time_wait

found that the system has a large number of time_wait state connections, by adjusting the kernel parameters to resolve,

Vi/etc/sysctl.conf


Edit the file and add the following:
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30

Then execute the /sbin/sysctl -p parameters to take effect.

net.ipv4.tcp_syncookies = 1 means that SYN Cookies are turned on. When there is a SYN wait queue overflow, cookies are enabled to protect against a small number of SYN attacks, the default is 0, which means close;


Net.ipv4.tcp_tw_reuse = 1 means turn on reuse. Allows time-wait sockets to be re-used for new TCP connections, which defaults to 0, which means shutdown;


net.ipv4.tcp_tw_recycle = 1 means a fast recycle of time-wait sockets in the TCP connection is turned on, and the default is 0, which means shutdown.


net.ipv4.tcp_fin_timeout Modify the default timeout time for the system

After modification, use

[Email protected] mysql_log]# Netstat-ntu |grep TIME_WAIT|WC

0 0 0


Found a large number of time_wait no longer exist, MySQL process occupancy rate quickly down, the site access is normal!!

The above is only a temporary solution, the last careful inspection found is the day before the new online system, the program code is not used Mysql.colse (), resulting in a large number of MySQL time_wait


This article is from the "believe it or not you" blog, please be sure to keep this source http://312461613.blog.51cto.com/965442/1562473

MySQL server discovers a number of time_wait solutions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.