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

查看:379
本文介绍了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.

此外,您还需要考虑TIMED_WAIT状态.关闭TCP套接字后(默认情况下),端口在TIMED_WAIT状态下保持已占用 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内容.

P.S. TIMED_WAIT的原因是为了处理在套接字关闭后到达数据包的情况.之所以会发生这种情况,是因为数据包延迟了,或者另一端只是不知道套接字已经关闭.这样,操作系统就可以静默丢弃那些数据包,而不会感染"另一个不相关的套接字连接.

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天全站免登陆