How to check the number of open connections in node.js?
Hey Joey! I was looking for a unix solution that would help me figure out how many open connections at a given moment anytime on my machine. The reason was my server was not able to handle requests after a certain number of connections. And figured that my machine can handle only 1024 open connections at a time i.e., the ulimit file descriptor value which defaults to 1024. I have modified this value by setting ulimit -n that suits my requirement.
So to check the open connections I used lsof that gives me the list of open files and figured how many connections are open via each port I was using.
You can get the count of connections by using below:
var server = http.createServer(app);
server.getConnections(function(error, count) {
console.log(count);
});
Using this you keep check on connection and when it cross a threshold then close the previous connections. Hope it helps.