Apachebench 请求计数和 Node.js 脚本计数器不匹配
毫无疑问我在做一些愚蠢的事情,但我在使用 Nerve 微框架运行一个简单的 Node.js 应用程序时遇到了问题。使用 apachebench 进行测试,似乎我的单个控制器中的代码被调用的频率比应用程序本身被调用的频率更高。
我创建了一个测试脚本,如下所示:
'use strict';
(function () {
var path = require('path');
var sys = require('sys');
var nerve = require('/var/www/libraries/nerve/nerve');
var nerveCounter = 0;
r_server.on("error", function (err) {
console.log("Error " + err);
});
var app = [
["/", function(req, res) {
console.log("nc = " + ++nerveCounter);
}]
];
nerve.create(app).listen(80);
}());
启动服务器。从另一个盒子运行负载测试:
/usr/sbin/ab -n 5000 -c 50 http://<snip>.com/
...
Complete requests: 5000
...
Percentage of the requests served within a certain time (ms)
...
100% 268 (longest request)
但节点脚本本身一直打印到:
nc = 5003
rc = 5003
换句话说,服务器被调用 5000 次,但控制器代码被调用 5003 次。
有什么想法我做错了吗?
已更新
我显着改变了这个问题的语气和内容,以反映 Colum、Alfred 和 GregInYEG 给我的帮助,让我意识到问题不在于 Redis 或 Nerve,而可能在于 apachebench。
No doubt I'm doing something stupid, but I've been having problems running a simple node.js app using the Nerve micro-framework. Testing with apachebench, it seems that the code within my single controller is being invoked more frequently than the app itself is being called.
I've created a test script like so:
'use strict';
(function () {
var path = require('path');
var sys = require('sys');
var nerve = require('/var/www/libraries/nerve/nerve');
var nerveCounter = 0;
r_server.on("error", function (err) {
console.log("Error " + err);
});
var app = [
["/", function(req, res) {
console.log("nc = " + ++nerveCounter);
}]
];
nerve.create(app).listen(80);
}());
Start the server. From another box, run a load test:
/usr/sbin/ab -n 5000 -c 50 http://<snip>.com/
...
Complete requests: 5000
...
Percentage of the requests served within a certain time (ms)
...
100% 268 (longest request)
But the node script itself is printing all the way up to:
nc = 5003
rc = 5003
In other words, the server is being called 5000 times but the controller code is being called 5003 times.
Any ideas what I'm doing wrong?
Updated
I changed the tone and content of this question significantly to reflect the help Colum, Alfred and GregInYEG gave me in realising that the problem did not lie with Redis or Nerve and probably lie with apachebench.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
程序:
结论
它在我的计算机上运行没有任何缺陷:
Program:
Conclusion
It works without any flaws on my computer: