I was trying Socket.io (server and client) for my personal project. As it is my first try with node.js even javascript and mongodb I am bit confused about performance of my server.
I have created a complex real time system with many events and many rooms. Server have very limited events but clients have too many events. These events are distributed under rooms.
For example -
Room R1 >> Event R1E1, Event R1E2, Event R1E3.... Event R1EN
Room R2 >> Event R2E1, Event R2E2, Event R2E3.... Event R2EN
All the data is stored in mongodb. Working awesome.
But issue arise when few clients (5-8) with 10-15 events registered start sending data. Server initially works fine but after couple of minutes it stops responding. Clients stay connected even server is not responding. Requests are pile up. Sometime server receive last sessions request.
It all start when the ultimate device start registering events. So I want to know how many events a socket.io can handle ?
P.S. Here what I think "event" is -
io.on('event', function(msg){
console.log( msg);
});
Edit 2
As I studied about node.js, a node is basically a process which runs on a single thread, if it requires to process other things it starts another node (an async thread), leaves new thread alone doing it's process and return to main thread running. If we want to process some sequences of process we use "async/await".
In my case I am using async at only one place when client first connect. Here I query 3 different collections of mongodb and return the data on an event.
My server is currently running on a MacBook pro (16 GB RAM, i7 6th gen quad core). It should handle at least 4-6 concurrent threads.
I have created a load test, 100000 different events distributed under 1000 rooms with 5 request per second querying db. It was working fine. Almost 40% RAM and 250% CPU was max laod.
My connection to db is persistent mean I connect to db as soon as server starts and keep that connection reference alive.
So what is the issue?