2009-11-06 13:42:56 +01:00
|
|
|
// This test requires the program "ab"
|
2010-03-09 00:06:29 +01:00
|
|
|
require("../common");
|
2009-11-06 13:42:56 +01:00
|
|
|
http = require("http");
|
2010-03-24 05:10:01 +01:00
|
|
|
exec = require("child_process").exec;
|
2009-11-06 13:42:56 +01:00
|
|
|
|
|
|
|
body = "hello world\n";
|
|
|
|
server = http.createServer(function (req, res) {
|
2010-02-25 21:54:48 +01:00
|
|
|
res.writeHead(200, {
|
2009-11-06 13:42:56 +01:00
|
|
|
"Content-Length": body.length,
|
|
|
|
"Content-Type": "text/plain",
|
|
|
|
});
|
2010-02-17 07:16:29 +01:00
|
|
|
res.write(body);
|
2010-02-17 20:10:10 +01:00
|
|
|
res.close();
|
2009-11-06 13:42:56 +01:00
|
|
|
});
|
|
|
|
server.listen(PORT);
|
|
|
|
|
|
|
|
var keepAliveReqSec = 0;
|
|
|
|
var normalReqSec = 0;
|
|
|
|
|
|
|
|
|
|
|
|
function runAb(opts, callback) {
|
2010-02-20 01:55:46 +01:00
|
|
|
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/";
|
2010-03-24 05:10:01 +01:00
|
|
|
exec(command, function (err, stdout, stderr) {
|
2010-02-20 03:54:25 +01:00
|
|
|
if (err) {
|
|
|
|
puts("ab not installed? skipping test.\n" + stderr);
|
|
|
|
process.exit();
|
|
|
|
return;
|
|
|
|
}
|
2010-02-20 01:55:46 +01:00
|
|
|
if (err) throw err;
|
|
|
|
var matches = /Requests per second:\s*(\d+)\./mi.exec(stdout);
|
|
|
|
var reqSec = parseInt(matches[1]);
|
|
|
|
|
|
|
|
matches = /Keep-Alive requests:\s*(\d+)/mi.exec(stdout);
|
|
|
|
var keepAliveRequests;
|
|
|
|
if (matches) {
|
|
|
|
keepAliveRequests = parseInt(matches[1]);
|
|
|
|
} else {
|
|
|
|
keepAliveRequests = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(reqSec, keepAliveRequests);
|
|
|
|
});
|
2009-11-06 13:42:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) {
|
|
|
|
keepAliveReqSec = reqSec;
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(true, keepAliveRequests > 0);
|
2009-11-06 13:42:56 +01:00
|
|
|
puts("keep-alive: " + keepAliveReqSec + " req/sec");
|
|
|
|
|
|
|
|
runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) {
|
|
|
|
normalReqSec = reqSec;
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(0, keepAliveRequests);
|
2009-11-06 13:42:56 +01:00
|
|
|
puts("normal: " + normalReqSec + " req/sec");
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
process.addListener("exit", function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(true, normalReqSec > 50);
|
|
|
|
assert.equal(true, keepAliveReqSec > 50);
|
|
|
|
assert.equal(true, normalReqSec < keepAliveReqSec);
|
2009-11-06 13:42:56 +01:00
|
|
|
});
|