现代 Linux 机器可以拥有的理论最大开放 TCP 连接数是多少? [英] What is the theoretical maximum number of open TCP connections that a modern Linux box can have

查看:26
本文介绍了现代 Linux 机器可以拥有的理论最大开放 TCP 连接数是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设硬件性能无限,Linux 机器能支持>65536 个打开的 TCP 连接吗?

Assuming infinite performance from hardware, can a Linux box support >65536 open TCP connections?

我了解临时端口的数量 (<65536) 限制了从一个本地 IP 到一个远程 IP 上的一个端口的连接数.

I understand that the number of ephemeral ports (<65536) limits the number of connections from one local IP to one port on one remote IP.

元组(本地ip、本地端口、远程ip、远程端口)是唯一定义一个TCP连接的东西;这是否意味着如果这些参数中有多个是空闲的,则可以支持超过 65K 的连接.例如从多个本地 IP 连接到多个远程主机上的单个端口号.

The tuple (local ip, local port, remote ip, remote port) is what uniquely defines a TCP connection; does this imply that more than 65K connections can be supported if more than one of these parameters are free. e.g. connections to a single port number on multiple remote hosts from multiple local IPs.

系统中是否还有其他 16 位限制?大概有多少个文件描述符?

Is there another 16 bit limit in the system? Number of file descriptors perhaps?

推荐答案

一个监听端口可以同时接受多个连接.

A single listening port can accept more than one connection simultaneously.

经常提到64K"限制,但这是每个客户端每个服务器端口,需要澄清.

There is a '64K' limit that is often cited, but that is per client per server port, and needs clarifying.

每个 TCP/IP 数据包基本上都有四个用于寻址的字段.它们是:

Each TCP/IP packet has basically four fields for addressing. These are:

source_ip source_port destination_ip destination_port
<----- client ------> <--------- server ------------>

在 TCP 堆栈内部,这四个字段用作复合键以将数据包与连接(例如文件描述符)进行匹配.

Inside the TCP stack, these four fields are used as a compound key to match up packets to connections (e.g. file descriptors).

如果一个客户端有许多连接到同一个目的地的同一个端口,那么其中三个字段将是相同的——只有 source_port 不同以区分不同的连接.端口是 16 位数字,因此任何给定客户端与任何给定主机端口的最大连接数为 64K.

If a client has many connections to the same port on the same destination, then three of those fields will be the same - only source_port varies to differentiate the different connections. Ports are 16-bit numbers, therefore the maximum number of connections any given client can have to any given host port is 64K.

但是,多个客户端每个最多可以有 64K 连接到某个服务器的端口,如果服务器有多个端口或者其中一个是多宿主的,那么您可以进一步增加.

However, multiple clients can each have up to 64K connections to some server's port, and if the server has multiple ports or either is multi-homed then you can multiply that further.

所以真正的限制是文件描述符.每个单独的套接字连接都有一个文件描述符,因此限制实际上是系统配置为允许的文件描述符数量和要处理的资源.最大限制通常超过 300K,但可以配置,例如使用 sysctl.

So the real limit is file descriptors. Each individual socket connection is given a file descriptor, so the limit is really the number of file descriptors that the system has been configured to allow and resources to handle. The maximum limit is typically up over 300K, but is configurable e.g. with sysctl.

普通盒子的实际限制约为 80K,例如单线程 Jabber 消息服务器.

The realistic limits being boasted about for normal boxes are around 80K for example single threaded Jabber messaging servers.

这篇关于现代 Linux 机器可以拥有的理论最大开放 TCP 连接数是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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