保持 1,000,000 个 websocket 打开需要多少系统资源? [英] How many system resources will be held for keeping 1,000,000 websocket open?

查看:49
本文介绍了保持 1,000,000 个 websocket 打开需要多少系统资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Websocket 不错,但它能否处理 1,000,000 个并发连接?
保持 1,000,000 个 websocket 打开将占用多少系统资源?

Websocket is good, but would it be able to handle 1,000,000 concurrent connections?
How many system resources will be held for keeping 1,000,000 websocket open?

推荐答案

更新答案

简短回答:是的,但价格昂贵.

长答案:

这个问题不是 WebSockets 独有的,因为 WebSockets 从根本上是长寿命的 TCP 套接字,具有类似 HTTP 的握手和最少的消息帧.

This question is not unique to WebSockets since WebSockets are fundamentally long-lived TCP sockets with a HTTP-like handshake and minimal framing for messages.

真正的问题是:单个服务器能否同时处理 1,000,000 个套接字连接,这会消耗哪些服务器资源?答案因多种因素而变得复杂,但对于大小合适的系统(大量 CPU、RAM 和快速网络)以及经过调整的服务器系统和优化的服务器软件,1,000,000 个同时活动套接字连接是可能的.

The real question is: could a single server handle 1,000,000 simultaneous socket connections and what server resources would this consume? The answer is complicated by several factors, but 1,000,000 simultaneous active socket connections is possible for a properly sized system (lots of CPU, RAM and fast networking) and with a tuned server system and optimized server software.

连接数不是主要问题(这主要是内核调整和足够内存的问题),它是处理和向/从每个连接发送/接收数据的问题.如果传入的连接在很长一段时间内分散开来,并且它们大多处于空闲状态或很少发送小块静态数据,那么您可能会得到远高于 1,000,000 个同时连接的数据.但是,即使在这些情况下(连接速度慢且大部分处于空闲状态),您仍然会遇到网络、服务器系统和服务器库的问题,这些问题未经过配置和设计来处理大量连接.

The number of connections is not the primary problem (that's mostly just a question of kernel tuning and enough memory), it is the processing and sending/receiving data to/from each of those connections. If the incoming connections are spread out over a long period, and they are mostly idle or infrequently sending small chunks of static data then you could probably get much higher than even 1,000,000 simultaneous connections. However, even under those conditions (slow connections that are mostly idle) you will still run into problems with networks, server systems and server libraries that aren't configured and designed to handle large numbers of connections.

请参阅 Alessandro Alinone 关于 500,000 个连接的近似资源使用情况的回答.

See Alessandro Alinone's answer about approximate resource usage for 500,000 connections.

这里有一些较旧但仍然适用的资源,可以阅读有关如何配置服务器和编写服务器软件以支持大量连接的信息:

Here are some older but still applicable resources to read on how you would configure your server and write your server software to support large numbers of connections:

这篇关于保持 1,000,000 个 websocket 打开需要多少系统资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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