Linux 服务器的单个端口(套接字)上的最大并发连接数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2350071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:48:44  来源:igfitidea点击:

Maximum number of concurrent connections on a single port (socket) of Server

linuxsocketsnetwork-programmingclient-servertelnet

提问by Karthik Balaguru

What could be the maximum number of concurrent Clients (using different port number) that could communicate to a Server on the same port (Single socket) ? What are the factors that could influence this count ? I am looking for this information w.r.t telnet in Linux environment.

可以与同一端口(单套接字)上的服务器通信的并发客户端(使用不同端口号)的最大数量是多少?影响这个计数的因素有哪些?我正在 Linux 环境中通过 telnet 查找此信息。

回答by cletus

This depends in part on your operating system.

这部分取决于您的操作系统。

There is however no limit on a specific port. There is a limit on the number of concurrent connections however, typically limited by the number of file descriptors the kernel supports (eg 2048).

但是,对特定端口没有限制。然而,并发连接的数量是有限制的,通常受限于内核支持的文件描述符数量(例如 2048)。

The thing to remember is that a TCP connection is unique and a connection is a pair of end points (local and remote IP address and port) so it doesn't matter if 1000 connections connect to the same port on a server because the connections are all still unique because the other end is different.

需要记住的是,TCP 连接是唯一的,连接是一对端点(本地和远程 IP 地址和端口),因此 1000 个连接是否连接到服务器上的同一端口并不重要,因为这些连接是一切仍然独一无二,因为另一端是不同的。

The other limit to be aware of is that a machine can only make about 64K outbound connections or the kernel limit on connections, whichever is lower. That's because port is an unsigned 16 bit number (0-65535) and each outbound connection uses one of those ports.

另一个需要注意的限制是一台机器只能建立大约 64K 的出站连接或内核对连接的限制,以较低者为准。这是因为端口是一个无符号的 16 位数字 (0-65535),并且每个出站连接都使用这些端口之一。

You can extend this by giving a machine additional IP addresses. Each IP address is another address space of 64K addresses.

您可以通过为机器提供额外的 IP 地址来扩展它。每个 IP 地址是另一个 64K 地址的地址空间。

回答by MarkR

More than you care about. Or rather.

比你关心的更多。更确切地说。

  • More than your code can actually handle (for other reasons)
  • More than your clients will actually make
  • More than you can handle on a single box for performance reasons
  • More than you need on a single box because your load balancers will distribute them amongst several for availability reasons anyway
  • 超出您的代码实际处理能力(出于其他原因)
  • 比您的客户实际赚的多
  • 出于性能原因,您无法在单个盒子上处理更多
  • 多于您在单个盒子上的需求,因为无论如何您的负载平衡器都会出于可用性原因将它们分配给多个

I can guarantee that it is more than all of those. There are scalability limitations with large numbers of sockets, which can be worked around (Google for the c10k problem). In practice it is possible to have more than 10,000 sockets usefully used by a single process under Linux. If you have multiple processes per server, you can increase that up again.

我可以保证它比所有这些都多。大量套接字存在可扩展性限制,可以解决(谷歌解决 c10k 问题)。在实践中,Linux 下的单个进程可能有超过 10,000 个有用的套接字。如果每个服务器有多个进程,您可以再次增加它。

It is not necessary to use a single port, as your dedicated load-balancers will be able to round-robin several ports if needed.

没有必要使用单个端口,因为如果需要,您的专用负载平衡器将能够循环多个端口。

If you are running a service for many 10s of 1000s of client processes, it is probably fairly important that it keeps working, therefore you will need several servers for redunancy ANYWAY. Therefore you won't have a problem deploying a few more servers.

如果您正在为成百上千个客户端进程运行服务,那么它继续工作可能相当重要,因此无论如何您都需要多个服务器来实现冗余。因此,部署更多服务器不会有问题。

回答by henrietta

I did a testing on Windows, doing multiple loopback connections onto a single socket. Windows refused to allocate anything after 16372 mark.

我在 Windows 上做了一个测试,在一个套接字上做多个环回连接。Windows 拒绝在 16372 标记之后分配任何内容。