Websockets 和可扩展性 [英] Websockets and scalability

查看:50
本文介绍了Websockets 和可扩展性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 websockets 的初学者.在我的应用程序中需要在发生变化时服务器需要通知客户端并且我打算使用 websockets.

Am a beginner with websockets. Have a need in my application where server needs to notify clients when something changes and am planning to use websockets.

  1. 单个服务器实例和单个客户端 ==>将创建多少个 websockets 以及有多少个 websockets 连接?

  1. Single server instance and single client ==> How many websockets will be created and how many connections to websockets?

单个服务器实例和 10 个客户端 ==>将创建多少个 websockets 以及有多少个 websockets 连接?

Single server instance and 10 clients ==> How many websockets will be created and how many connections to websockets?

单个服务器实例和 1000 个客户端 ==>将创建多少个 websockets 以及有多少个 websockets 连接?

Single server instance and 1000 clients ==> How many websockets will be created and how many connections to websockets?

当您的应用程序拥有 1000 多个用户群时,您如何使用 webscokets 进行扩展?

How do you scale with webscokets when your application has a 1000’s of user base?

非常感谢您的反馈.

推荐答案

1) 单个服务器实例和单个客户端 ==> 将创建多少个 websockets 以及有多少个 websockets 连接?

1) Single server instance and single client ==> How many websockets will be created and how many connections to websockets?

如果您的客户端创建了一个 webSocket 连接,那么这就是客户端上的一个 webSocket 连接和服务器上的一个.客户端创建到服务器的 webSocket 连接,因此客户端决定了连接的数量.如果它创建了 3,那么就会有 3.如果它创建了 1,那么就会有 1.通常,客户端只会创建 1.

If your client creates one webSocket connection, then that's what there will be one webSocket connection on the client and one on the server. It's the client that creates webSocket connections to the server so it is the client that determines how many there will be. If it creates 3, then there will be 3. If it creates 1, then there will be 1. Usually, the client would just create 1.

2) 单个服务器实例和 10 个客户端 ==> 将创建多少个 websockets 以及有多少个 websockets 连接?

2) Single server instance and 10 clients ==> How many websockets will be created and how many connections to websockets?

如上所述,这取决于客户端做什么.如果每个客户端创建 1 个 webSocket 连接,并且有 10 个客户端连接到服务器,那么服务器将看到总共 10 个 webSocket 连接.

As described above, it depends upon what the client does. If each client creates 1 webSocket connection and there are 10 clients connected to the server, then the server will see a total of 10 webSocket connections.

3) 单个服务器实例和 1000 个客户端 ==> 将创建多少个 websockets 以及有多少个 websockets 连接?

3) Single server instance and 1000 clients ==> How many websockets will be created and how many connections to websockets?

与第 2 点相同.

当您的应用程序拥有 1000 多个用户群时,您如何使用 webscokets 进行扩展?

How do you scale with webscokets when your application has a 1000’s of user base?

适当配置的单个服务器可以同时处理数十万个 webSocket 连接,这些连接大多处于空闲状态,因为空闲的 webSocket 几乎不使用服务器 CPU.对于更大规模的部署,可以将服务器集群化(运行多个服务器进程)并使用粘性负载平衡来分散负载.

A single server, configured appropriately can handle hundreds of thousands of simultaneous webSocket connections that are mostly idle since an idle webSocket uses pretty much no server CPU. For even larger scale deployments, one can cluster the server (run multiple server processes) and use sticky load balancing to spread the load.

如果您正在寻求大规模的 webSocket 或 socket.io 部署,那么 Google 上还有许多其他类似的文章值得一读:

There are many other articles like these on Google worth reading if you're pursuing large scale webSocket or socket.io deployments:

凤凰城 200 万个 Websocket 连接之路

600kAWS 上使用 Node.js 的并发 websocket 连接

1000 万个并发 webSockets

最终,每个正确配置的服务器可实现的规模可能更多地与每个连接有多少活动以及需要多少计算来实现.

Ultimately, the achievable scale per a properly configured server will likely have more to do with how much activity there is per connection and how much computation is needed to deliver that.

这篇关于Websockets 和可扩展性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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