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

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

谢谢。

最佳答案

当我想仔细检查数字 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);

关于javascript - 每秒从 node.js http 服务器获取请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16477174/

相关文章:

node.js - Node 长路径模块名称失败 teamcity 构建

javascript - 使用 node.js http-proxy 测量流量

node.js http-proxy 如何根据请求设置超时和处理程序

angularjs - 在执行 gulp build :dist 时设置代理或后端 URL

javascript - Vue 和带模板标签的条件渲染

javascript - 在执行回调后执行一些事情

node.js - Puppeteer 与 Express Router Node JS 的并行性。如何在保持并发的情况下在路由之间传递页面

node.js - 带环回的电子邮件连接器 3

javascript - 无法获取 HTMLCollection 长度

javascript - 将元素固定在顶部的特定偏移处,然后在滚动 1000 像素后释放