Websockets and scalability

落爺英雄遲暮 提交于 2019-12-03 18:42:15

问题


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) Single server instance and single client ==> How many websockets will be created and how many connections to websockets?

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

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

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

Thanks much for your feedback.


回答1:


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

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) Single server instance and 10 clients ==> How many websockets will be created and how many connections to websockets?

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) Single server instance and 1000 clients ==> How many websockets will be created and how many connections to websockets?

Same as point #2.

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

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.

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

The Road to 2 Million Websocket Connections in Phoenix

600k concurrent websocket connections on AWS using Node.js

10 million concurrent 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.



来源:https://stackoverflow.com/questions/47268038/websockets-and-scalability

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!