2

Is there a way in node.js to get the number of open connections and number of requests per second from a http server?

Assume the following simple server:

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end("Hello World!");
}).listen(80);

Thanks.

3
  • You can use ApacheBench or httperf. Commented May 10, 2013 at 7:32
  • I want these numbers from the server (node.js), not client. Commented May 10, 2013 at 7:35
  • Ah right. Check out node-measured. Commented May 10, 2013 at 7:51

1 Answer 1

9

This is what I usually do when I want to double-check numbers ab/httperf/wrk/siege report:

var served = 0;
var concurrent = 0;

http.createServer(function (req, res) {
  concurrent++;
  res.writeHead(200, {'Content-Type': 'text/plain'});
  setTimeout(function() { // emulate some async delay
    served++;
    concurrent--;
    res.end("Hello World!");
  }, 10);
}).listen(80);

setInterval(function() {
  console.log('Requests per second:' + served);
  console.log('Concurrent requests:' + concurrent);
  served = 0;
}, 1000);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.