对于所有连接,重复使用相同的端口是否会产生性能影响?

发布于 2025-02-01 21:08:13 字数 332 浏览 2 评论 0原文

WebSockets/HTTPS的标准是端口443,世界各地的每个客户端都在服务器端口443上连接。这一开始让我感到困惑,因为我想象所有流经单个实体的流量,如果有一个单一的瓶颈,那将是一个疯狂的瓶颈实体为所有网络流量提供服务。然后,我了解到“端口”只是一个数字,客户和服务器上的实际实体是插座。插座连接到端口,以便内核知道要转发传入的流量到哪个插座(如果这是错误的话,请纠正我)。因此,插座是一个比端口更高的实体。

我的问题是,让所有流量转到服务器上的一个端口是否有任何性能差异。要正确地向套接字传递流量,必须需要更多信息(也许是客户端主机名/端口?)。鉴于每个客户端在服务器端使用唯一的端口,仅服务器端口就足以脱离Multiplex。

The standard for WebSockets/HTTPS is port 443 and every single client around the world connects on server port 443. This confused me at first because I was imagining all traffic flowing through a single entity and it would be an insane bottleneck if there were a single entity servicing all web traffic. Then I learned that the "port" is just a number and the actual entity on clients and servers are sockets. Sockets are attached to ports so that the kernel knows which socket to forward incoming traffic to (please correct me if this is wrong). So sockets are a higher-level entity than ports.

My question is whether there is any performance difference at all to having all traffic go to a single port on the server. To properly de-multiplex incoming traffic to a socket, more information must be needed (maybe the client hostname/port?). Whereas if every client were using a unique port on the server side, the server port alone would be sufficient to de-multiplex.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℉絮湮 2025-02-08 21:08:14

我的问题是是否有任何性能差异
让所有流量转到服务器上的一个端口。正确
向插座的脱氧流动流量,更多信息必须是
需要(也许客户端主机名/端口?)。

假设所有流量无论如何都将转到同一程序(即对Web服务器过程),那么将所有流量放在单个端口上都可能比使用多个端口更有效,因为Web服务器只需要处理一个插座接受连接,而不是为许多端口中的每个端口创建一个单独的套接字。

TCP connections are uniquely identified by a

,如果每个客户端在服务器端使用唯一端口,则
仅服务器端口就足以脱落。

但是,这样做会将服务器限制在相对较少的客户端,因为任何给定主机上只有65535个端口(端口字段宽16位),并且许多端口可能已经用于其他服务。 ...并且服务器将必须创建每个分配的端口一个套接字,这很快就会变得笨拙。因此,给每个客户一个独特的端口会引起港口数量争夺的问题,而实际上并没有加快任何加速。

My question is whether there is any performance difference at all to
having all traffic go to a single port on the server. To properly
de-multiplex incoming traffic to a socket, more information must be
needed (maybe the client hostname/port?).

Assuming all the traffic is going to the same program anyway (i.e. to the web server process), then having all the traffic come in on a single port is likely to be more efficient than using multiple ports, since the web server needs only deal with a single socket to accept connections, rather than having to create a separate socket for each of a number of ports.

TCP connections are uniquely identified by a 5-tuple (source IP, source port, destination IP, destination port, protocol), so the amount of work it takes the network stack to de-multiplex incoming traffic will be the same (hashing the 5-tuple) regardless of how many ports are in use.

Whereas if every client were using a unique port on the server side,
the server port alone would be sufficient to de-multiplex.

However, doing that would limit the server to a relatively small number of clients, since there are only 65535 ports available on any given host (the port field is 16 bits wide), and many of those ports may already be in use for other services... and the server would have to create one socket per allocated port, which would quickly get unwieldy. So giving every client a unique port would cause problems with port-number contention, while not actually speeding anything up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文