Solution for Linux to improve load capacity for short connections

Source: Internet
Author: User

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:

 
 
  1. #define TCP_TIMEWAIT_LEN (60*HZ) /* how long to wait to destroy TIME-WAIT  
  2. * 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

 
 
  1. #define TCP_TIMEWAIT_LEN (10*HZ) /* how long to wait to destroy TIME-WAIT  
  2. * 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.

  1. Key Points of Linux cluster technology
  2. Another Linux server cluster software for LifeKeeper
  3. Linux server cluster technology
  4. Step 7: Protect Linux servers
  5. Introduction to ntop configuration in Linux

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.