Time_wait too much problem solving under Linux

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/jaylong35/article/details/6605077

Cause of the problem:

Self-developed a server and client, through a short connection to communicate, due to too frequent creation of connections, resulting in the number of system connections are occupied, can not be released in a timely manner. Looked at the 18888, then frightened.

Phenomenon:

1, the external machine can not properly connect SSH

2, inside outside can not normal ping pass, domain name also cannot normal parse.

Troubleshoot the problem:

by NETSTAT-ANP | grep time_wait | Wc-l command to see the number, found that the number of connections time_wait more than 18000 is too exaggerated.

1, the initial suspicion is that the program did not close the connection, Codereview two times, found that has been normally closed.

2, online to see the cause of time_wait, it may be because the server actively shut down the connection caused by time_wait generation.

3. Find Time_wait Solution:

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/sbin/sysctl-p to let the parameters take effect.

After the configuration, the temporary problem is resolved, and then see the number of time_wait quickly decline.

Key commands:

1、netstat -n | awk ‘/^tcp/ {++state[$NF]} END {for(key in state) print key,"\t",state[key]}‘

You will get a result similar to the following, the exact number will be different:

Last_ack 1
Syn_recv 14
Established 79
Fin_wait1 28
Fin_wait2 3
CLOSING 5
Time_wait 1669

Status: Description
CLOSED: No connection is active or in progress
LISTEN: The server is waiting to enter the call
SYN_RECV: A connection request has arrived, waiting for confirmation
Syn_sent: Application has started, open a connection
Established: Normal data transfer status
FIN_WAIT1: Application says it's done
Fin_wait2: The other side has agreed to release
Itmed_wait: Waiting for all packets to die
CLOSING: Both sides try to close simultaneously
Time_wait: The other side has initialized a release
Last_ack: Waiting for all packets to die

2, Sysctl-a | grep Time | grep wait
net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120
Net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60
net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120

Time_wait too much problem solving under Linux

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.