从node.js http服务器每秒获取请求

时间:2013-05-10 07:23:06

标签: javascript node.js node-http-proxy

node.js是否有办法从http服务器获取打开连接数每秒请求数

假设以下简单服务器:

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

感谢。

1 个答案:

答案 0 :(得分:8)

当我想仔细检查数字ab / httperf / wrk / siege报告时,我通常会这样做:

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);