2

有没有办法从 http 服务器node.js获取打开的连接数和每秒的请求数?

假设以下简单服务器:

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

谢谢。

4

1 回答 1

9

当我想仔细检查数字 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);
于 2013-05-10T12:18:43.790 回答