【发布时间】:2015-01-12 23:15:21
【问题描述】:
我有一个 nodejs 服务器。我想在这个服务器上测试 node-toobusy 模块。 我编写了一个客户端代码同时命中该服务器以使 cpu 使用率达到 100%,但我仍然无法使该模块工作。 PFB 服务器代码
var toobusy = require('toobusy'),
express = require('express');
var app = express();
// middleware which blocks requests when we're too busy app.use(function(req, res, next) {
if (toobusy()) {
res.send(503, "I'm busy right now, sorry."); console.log("hi");
} else {
next();
console.log("hi");
}
});
console.log("hi");
app.get('/', function(req, res) {
// processing the request requires some work!
var i = 0;
while (i < 1e5) i++;
res.send("I counted to " + i);
console.log("hi");
});
var server = app.listen(3005);
process.on('SIGINT', function() {
server.close();
// calling .shutdown allows your process to exit normally toobusy.shutdown();
process.exit();
});
关于如何使用该模块的任何想法都会非常有帮助。
【问题讨论】:
-
试着数到无穷大:)
标签: node.js cpu-usage node-modules