I've got a Node.js server which accepts potentially tens of thousands of socket.io connections.
For each socket, I need to have some sort of interval (using setInterval()) to inform an in-memory database that the socket is still active. This is purely for garbage collection purposes - When a socket is deemed inactive, its session data will be gc'd.
There are two naive approaches:
The first approach is more efficient for my application layer but will be harsher on the db because all requests will come at once (although not often).
The second way is nice because the database hits will be more evenly spread out but I'm not sure how harsh this will be on the application itself performance-wise.
So with this in mind, is it efficient to have tens of thousands of simultaneous intervals provided that they are very long (each about once every 10 minutes)?
The first approach might not be more harshe on the database, as you could update a lot of records at a time instead of making one database call for each socket.
By dividing up the sockets in batches of, say 1000, you could update the database records with a few database calls instead of tens of thousands of database calls.
It would be a bit of work for the database at that moment, but considering that you would otherwise make 10-20 database calls each second to update the socket information, you would probably lighten the load on the database overall.