1 // This test requires the program "ab"
2 process.mixin(require("./common"));
3 http = require("http");
7 body = "hello world\n";
8 server = http.createServer(function (req, res) {
10 "Content-Length": body.length,
11 "Content-Type": "text/plain",
18 var keepAliveReqSec = 0;
21 function error (msg) {
22 throw new Error("ERROR. 'ab' not installed? " + msg);
25 function runAb(opts, callback) {
26 sys.exec("ab " + opts + " http://127.0.0.1:" + PORT + "/")
28 .addCallback(function (out) {
29 var matches = /Requests per second:\s*(\d+)\./mi.exec(out);
30 var reqSec = parseInt(matches[1]);
32 matches = /Keep-Alive requests:\s*(\d+)/mi.exec(out);
33 var keepAliveRequests;
35 keepAliveRequests = parseInt(matches[1]);
37 keepAliveRequests = 0;
40 callback(reqSec, keepAliveRequests);
44 runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) {
45 keepAliveReqSec = reqSec;
46 assert.equal(true, keepAliveRequests > 0);
47 puts("keep-alive: " + keepAliveReqSec + " req/sec");
49 runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) {
50 normalReqSec = reqSec;
51 assert.equal(0, keepAliveRequests);
52 puts("normal: " + normalReqSec + " req/sec");
57 process.addListener("exit", function () {
58 assert.equal(true, normalReqSec > 50);
59 assert.equal(true, keepAliveReqSec > 50);
60 assert.equal(true, normalReqSec < keepAliveReqSec);