Reputation: 69
Is there a way to find the web request queue length when a lot of requests hit an express server route at the same time?
I can use the listener stats from Unix but I'm looking for a more native way to do it.
Upvotes: 1
Views: 706
Reputation: 298
This is achieved very easily. Somewhere in your program, you create a HTTP server like this:
const server = http.createServer(app);
All you need is to track incoming connections and count how many of them are open concurrently. I suppose you to store that number in app.connectionsN
field
app.connectionsN = 0;
const server = http.createServer(app);
server.on('connection', function(socket) {
// Increase connections count on newly estabilished connection
app.connectionsN ++;
socket.on('close', function() {
// Decrease connections count on closing the connection
app.connectionsN --;
});
});
Upvotes: 0