Answer the question
In order to leave comments, you need to log in
How to make the socket object global for all workers in a node?
I have a socket game. Because of the overload, I want to do optimization and now I'm smoking about clusters. The game requires you to constantly show the current online, users can make emits to other completely random users. But as I read the worker is a new isolated script and the sockets are separated on different ports. How can I calculate the total online and just get the right io.sockets.connected?
Answer the question
In order to leave comments, you need to log in
As an option, in a common radish for all, store its own online value for each worker, and when displaying online, sum it up over all workers and display it. It is not necessary to update the value in real time after each connection / disconnect (because there is usually no point in knowing the exact online), it is possible even with a frequency of several minutes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question