I've been "scaling out" a single-threaded socket.io app by using the cluster module long before node.js added worker threads.
But as having multiple processes involves (in my case) heavy usage of IPC, copying the same high-bandwidth data to all workers results in significant overhead. So instead - is it possible for socket.io to make use of worker threads? The goal is to use more than just one core.
I can think of two different ways that this may be possible:
- having multiple, completely separate socket.io instances, each running on its own worker thread (e.g. each servicing a different tcp port - that's how my current cluster solution works)
- having a single socket.io instance use multiple threads internally (in which case it would perhaps have to be doing something like epoll - so I kind of doubt socket.io has that built-in)
N.B. As worker threads are supposed to be used for performing CPU-intensive JavaScript operations, it remains to be seen how much can be gained by switching from multiple processes to multiple threads. But in general, I would not expect in-process to be slower than inter-process communication. Also, in the case of worker threads, data can be shared (rather than copied).