Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websockets and scalability

I am a beginner with websockets. I 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 websockets when your application has a 1000’s of user base?

Thanks much for your feedback.

like image 463
user3216514 Avatar asked Nov 13 '17 15:11

user3216514


People also ask

Why WebSockets are not scalable?

But why are WebSockets hard to scale? The main challenge is that connections to your WebSocket server need to be persistent. And even once you've scaled out your server nodes both vertically and horizontally, you also need to provide a solution for sharing data between the nodes.

What are the disadvantages of WebSockets?

The biggest downside to using WebSocket is the weight of the protocol and the hardware requirements that it brings with it. WebSocket requires a TCP implementation, which may or may not be a problem, but it also requires an HTTP implementation for the initial connection setup.

Are WebSockets vulnerable?

Some WebSockets security vulnerabilities arise when an attacker makes a cross-domain WebSocket connection from a web site that the attacker controls. This is known as a cross-site WebSocket hijacking attack, and it involves exploiting a cross-site request forgery (CSRF) vulnerability on a WebSocket handshake.

How do you horizontally scale a WebSocket?

Horizontal Scaling It needs to be configured with some other tools in order to build a fully scalable architecture. Using a Publish/Subscribe or pub/sub broker is an effective method of horizontally scaling WebSockets. There are several off-the-shelf solutions like Kafka or Redis that can make this happen.


1 Answers

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.

like image 135
jfriend00 Avatar answered Sep 21 '22 18:09

jfriend00