All we need is an easy explanation of the problem, so here it is.
I got a website that implements the broadcast.emit. that sends message to all users of the site. It is just the simplest implementation of socket.io but I currently having a problem. When I hit about 100 concurrent users. The nodejs server starts to lag until it hangs that I can no longer access my whole website. When we checked the server. The nodejs is taking 100% of the CPU. Is it normal?
I was wondering how many users can socket.io supports? And when this thing happen is there a way to restart the nodejs server programatically?
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
I have a multiplayer card game. Socket.io maxes out my CPU at around 3000 concurrent users. This is on Intel i7 CPU. Because of this I have to run multiple node/socket.io processes to handle the load.
For 100 concurrent connections you should be fine. Perhaps you are using some VPS and CPU is shared with all the other VMs? Do you run a dedicated server?
Also, check your code. You might be doing synchronously some stuff that should go async.
At least 250k concurrent connections (and for most use cases bottleneck is memory)
Is it critical for you to deliver message to all clients without dropping it? If no, I’d propose to use socket.volatile.emit call. There can be a lot of problems with remote clients and non-stable connectons.
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂