You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
I have a question about PM2 cluster in production as well as ClusterWs.
I conducted an experiment by laucnhing 4 child processes using PM2 (I have 4 cores on my machine). On the client I created multiple sockets, and sent many messages to the servers. One thing I didn't expect was that Node was able to figure out what child process the socket belonged to, therefore every message sent by the client was console logged by the correct child process.
It seems like the main worker in the cluster keeps track of what sockets belong where.
So does Nodejs do this using the "cluster" module?
Also is this ok in production? and can this aslo be achived with ClusterWs (in case I decide to use it instead)?
The text was updated successfully, but these errors were encountered:
sofasurfa
changed the title
Question: how webscokets connect to the correct child process inside a cluster?
Websockets inside a cluster, ok in production?
Sep 20, 2019
@sofasurfa sorry for late response, had quite a bit of work during the week. Websocket is consistent connection to particular server, main worker (master) is only responsible for load balance between different child processes (per request) websocket connection is single request which will be assigned to one child process and only communicate with that child (so when you send message through websocket you will always send it to the same node js child process). That is how it suppose to work and ClusterWS uses node js clustering under the hood so it has exactly the same behaviour. If your use case does not include any client to client communication then you dont really need clusterws (but most of the cases with websocket is sending messages between different clients)
ClusterWS is good for client to client/clients communication with scaling. For example you would like to send message from one client to another and you have 2 worker processes and this 2 clients are connected to different workers so you will need to set up some kind of worker to worker communication to be able to send message from one client to another. That is where clusterws comes (in general it simplifies cross workers communication)
@goriunov
I have a question about PM2 cluster in production as well as ClusterWs.
I conducted an experiment by laucnhing 4 child processes using PM2 (I have 4 cores on my machine). On the client I created multiple sockets, and sent many messages to the servers. One thing I didn't expect was that Node was able to figure out what child process the socket belonged to, therefore every message sent by the client was console logged by the correct child process.
It seems like the main worker in the cluster keeps track of what sockets belong where.
So does Nodejs do this using the "cluster" module?
Also is this ok in production? and can this aslo be achived with ClusterWs (in case I decide to use it instead)?
The text was updated successfully, but these errors were encountered: