Computer users abandon Microsoft and start to apply it. As a result, many people start to apply the Linux operating system. When learning about Linux, you may encounter the problem that the Linux system can cope with the load capacity of transient connections, here we will introduce how the Linux system solves the load capacity of transient connections. Here we will share with you. 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 to save 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 preceding
- #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 preceding section describes how to handle short-connection load in Linux.
- Key Points of Linux cluster technology
- Another Linux server cluster software for LifeKeeper
- Linux server cluster technology
- Step 7: Protect Linux servers
- Introduction to ntop configuration in Linux