tcp_tw_reuse 与 tcp_tw_recycle :使用哪个(或两者)? [英] tcp_tw_reuse vs tcp_tw_recycle : Which to use (or both)?

查看:25
本文介绍了tcp_tw_reuse 与 tcp_tw_recycle :使用哪个(或两者)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用大量连接的网站和应用程序.它通常静态打开大约 3,000 个连接,并且可以在几秒钟的时间内接收 5,000 到 50,000 次连接尝试.

I have a website and application which use a significant number of connections. It normally has about 3,000 connections statically open, and can receive anywhere from 5,000 to 50,000 connection attempts in a few seconds time frame.

由于 TIME_WAIT 状态套接字,我遇到了用尽本地端口来打开新连接的问题.即使将 tcp_fin_timeout 设置为一个较低的值 (1-5),这似乎只是造成了过多的开销/速度减慢,并且偶尔仍无法打开新套接字.

I have had the problem of running out of local ports to open new connections due to TIME_WAIT status sockets. Even with tcp_fin_timeout set to a low value (1-5), this seemed to just be causing too much overhead/slowdown, and it would still occasionally be unable to open a new socket.

我已经查看了 tcp_tw_reuse 和 tcp_tw_recycle,但我不确定其中哪一个是首选,或者是否可以同时使用它们.

I've looked at tcp_tw_reuse and tcp_tw_recycle, but I am not sure which of these would be the preferred choice, or if using both of them is an option.

推荐答案

根据 Linux 文档,您应该使用 TCP_TW_REUSE 标志来允许在 TIME_WAIT 状态下为新连接重用套接字.

According to Linux documentation, you should use the TCP_TW_REUSE flag to allow reusing sockets in TIME_WAIT state for new connections.

在处理必须处理许多处于 TIME_WAIT 状态的短 TCP 连接的 Web 服务器时,这似乎是一个不错的选择.

It seems to be a good option when dealing with a web server that have to handle many short TCP connections left in a TIME_WAIT state.

此处所述,使用负载均衡器时,TCP_TW_RECYCLE 可能会导致一些问题...

As described here, The TCP_TW_RECYCLE could cause some problems when using load balancers...

编辑(添加一些警告;)):

EDIT (to add some warnings ;) ):

正如@raittes 在评论中提到的,使用负载均衡器时的问题"是关于面向公众的服务器.启用回收后,服务器无法区分来自同一 NAT 设备后面的不同客户端的新传入连接.

as mentionned in comment by @raittes, the "problems when using load balancers" is about public-facing servers. When recycle is enabled, the server can't distinguish new incoming connections from different clients behind the same NAT device.

这篇关于tcp_tw_reuse 与 tcp_tw_recycle :使用哪个(或两者)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆