linux 上的机器之间的 tcp/ip 连接数量是否有限制? [英] Is there a limit on number of tcp/ip connections between machines on linux?

查看:23
本文介绍了linux 上的机器之间的 tcp/ip 连接数量是否有限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 5 分钟内编写了一个非常简单的程序,它打开一个服务器套接字并遍历请求并将发送给它的字节打印到屏幕上.

I have a very simple program written in 5 min that opens a sever socket and loops through the request and prints to the screen the bytes sent to it.

然后,我尝试对我可以锤击它的连接数进行基准测试,以找出我可以使用该程序支持多少并发用户.

I then tried to benchmark how many connections I can hammer it with to try to find out how many concurrent users I can support with this program.

在另一台机器上(它们之间的网络没有饱和)我创建了一个简单的程序,它进入一个循环并连接到服务器机器并发送字节hello world".

On another machine (where the network between them is not saturated) I created a simple program that goes into a loop and connects to the server machine and send the bytes "hello world".

当循环为 1000-3000 时,客户端完成所有请求的发送.当循环超过 5000 时,它在完成第一个 X 个请求后开始超时.为什么是这样?我已经确保在循环中关闭我的套接字.

When the loop is 1000-3000 the client finishes with all requests sent. When the loop goes beyond 5000 it starts to have time outs after finish the first X number of requests. Why is this? I have made sure to close my socket in the loop.

你能不能在一定时间内只创建这么多连接?

Can you only create so many connections within a certain period of time?

此限制是否仅适用于同一台机器之间,我不必担心在生产中出现这种情况,因为 5000 多个请求都来自不同的机器?

Is this limit only applicable between the same machines and I need not worry about this in production where 5000+ requests are all coming from different machines?

推荐答案

有一个限制,是的.参见 ulimit.

There is a limit, yes. See ulimit.

您还需要考虑 TIMED_WAIT 状态.一旦 TCP 套接字关闭(默认情况下),端口将在 TIMED_WAIT 状态下保持 occupied 2 分钟.该值是可调的.即使它们已关闭,这也会耗尽您的套接字".

Also you need to consider the TIMED_WAIT state. Once a TCP socket is closed (by default) the port remains occupied in TIMED_WAIT status for 2 minutes. This value is tunable. This will also "run you out of sockets" even though they are closed.

运行 netstat 以查看运行中的 TIMED_WAIT 内容.

Run netstat to see the TIMED_WAIT stuff in action.

附言TIMED_WAIT 的原因是为了处理socket关闭后数据包到达的情况.这可能是因为数据包被延迟或另一方只是不知道套接字已关闭.这允许操作系统以静默方式丢弃这些数据包,而不会感染"不同的、不相关的套接字连接.

P.S. The reason for TIMED_WAIT is to handle the case of packets arriving after the socket is closed. This can happen because packets are delayed or the other side just doesn't know that the socket has been closed yet. This allows the OS to silently drop those packets without a chance of "infecting" a different, unrelated socket connection.

这篇关于linux 上的机器之间的 tcp/ip 连接数量是否有限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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