Improve Linux's ability to cope with short connections.
Source: Internet
Author: User
Improve the load capacity of Linux to cope with transient connections-Linux Enterprise applications-Linux server application information. The following is a detailed description. In the case of a large number of short connections, the TCP stack of Linux usually generates a large number of TIME_WAIT sockets.
You can see with the following command:
Netstat-ant | grep-I time_wait
Sometimes, this number is astonishing:
Netstat-ant | grep-I time_wait | wc-l
It may exceed 30 thousands or 40 thousands. At this time, we need to modify the tcp time wait of linux kernel to shorten it. The sysctl parameter seems to be usable, Which is/proc/sys/net/ipv4/tcp_fin_timeout, the default value is 60, that is, 60 seconds. Many online documents say that setting this value to a lower value can reduce the TIME_WAIT status in netstat, but this statement is incorrect. After carefully reading the Linux kernel source code, we found that this value was actually used for output. After modification, it was not actually read back to the kernel for use, what really works in the KERNEL is a macro definition, in $ KERNEL/include/net/tcp. h contains the following lines:
# Define TCP_TIMEWAIT_LEN (60 * HZ)/* how long to wait to destroy TIME-WAIT
* State, about 60 seconds */
This macro controls the timeout time of the TCP TIME_WAIT state. If we want to reduce the number of TIME_WAIT states (thus saving a little kernel operation time), we can set this value to a lower value. According to our test, it is appropriate to set it to 10 seconds, that is, modify the above:
# Define TCP_TIMEWAIT_LEN (10 * HZ)/* how long to wait to destroy TIME-WAIT
* State, about 60 seconds */
Then re-compile the kernel and restart the system to find that the TIME_WAIT status caused by short connections is greatly reduced:
Netstat-ant | grep-I time_wait | wc-l
Generally, it can be reduced by at least 2/3. It can also speed up the system to cope with short connections.
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.