TCP short connection time_wait solution (5) -- tcp_max_tw_buckets

Source: Internet
Author: User

Refer to the official documentation (http://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt) for the following explanation:
Tcp_max_tw_buckets-INTEGER
Maximal number of timewait sockets held by system simultaneously.
If this number is exceeded time-wait socket is immediately destroyed
And warning is printed.
The official document does not describe the default value. After a few simple verification systems, it is preliminarily determined that the default value is 180000.

The source code shows that this option is relatively simple. The implementation code is as follows:
===== Linux-2.6.37 net/ipv4/tcp_minisocks.c 269 ======
Void tcp_time_wait (struct sock * sk, int state, int timeo)
{
Struct inet_timewait_sock * tw = NULL;
Const struct inet_connection_sock * icsk = inet_csk (sk );
Const struct tcp_sock * tp = tcp_sk (sk );
Int recycle_ OK = 0;

If (tcp_death_row.sysctl_tw_recycle & tp-> rx_opt.ts_recent_stamp)
Recycle_ OK = icsk-> icsk_af_ops-> remember_stamp (sk );

If (tcp_death_row.tw_count <tcp_death_row.sysctl_max_tw_buckets)
Tw = inet_twsk_alloc (sk, state );

If (tw! = NULL ){
// The allocation is successful and the TIME_WAIT status is processed. A lot of code is omitted here.
Else {
// Allocation failed, not processed, only logs recorded: TCP:
Time wait bucket table overflow
/* Sorry, if we're out of memory, just CLOSE this
* Socket up. We 've got bigger problems
* Non-graceful socket closings.
*/
NET_INC_STATS_BH (sock_net (sk), LINUX_MIB_TCPTIMEWAITOVERFLOW );
}

Tcp_update_metrics (sk );
Tcp_done (sk );
}
The test result shows that if the value is set to 100, the number of TIME_WAIT connections is stable at 100, and is not affected by the networking and other configurations.

There is a warning in the official manual:
This limit exists only to prevent
Simple DoS attacks, you _ must _ not lower the limit artificially,
But rather increase it (probably, after increasing installed memory ),
If network conditions require more than default value.
Basically, this is used to prevent DoS attacks. We should not manually reduce them. If network conditions are needed, they should increase.
But in fact, this risk is not big for our LAN or company intranet applications.

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.