Skip to content

Instantly share code, notes, and snippets.

@geNAZt
Created February 9, 2013 08:36
Show Gist options
  • Save geNAZt/4744602 to your computer and use it in GitHub Desktop.
Save geNAZt/4744602 to your computer and use it in GitHub Desktop.
var http = require('http'),
curReqs = 0,
responsetimes = [],
runTime = 120,
processed = 0,
child = require('child_process'),
path = require('path'),
start = 0,
server = http.createServer(function (req, res) {
"use strict";
curReqs += 1;
start = (new Date()).getTime();
if (req.headers.host === "www.house-of-code.org:1234") {
res.end("WWW");
responsetimes.push((new Date()).getTime() - start);
} else if (req.headers.host === "test.house-of-code.org:1234") {
res.end("Test");
responsetimes.push((new Date()).getTime() - start);
}
});
console.log("Testcase with 2 enabled VHosts without ExpressJS");
console.log("MegaBytes / Reqs / ms");
console.log("heapUsed rss reqs respAvg");
setInterval(function () {
"use strict";
var memory = process.memoryUsage(),
sum = 0,
i = 0,
avg = 0;
for (i = 0; i < responsetimes.length; i += 1) {
sum += parseInt(responsetimes[i], 10);
}
if (sum > 0) {
avg = sum / responsetimes.length;
}
responsetimes = [];
console.log((memory.heapUsed / (1024 * 1024)) + " " + (memory.rss / (1024 * 1024)) + " " + curReqs + " " + avg);
curReqs = 0;
}, 1000);
server.listen(1234, function () {
"use strict";
child.exec('"' + path.join(process.cwd(), "./bin/ab") + '" -n 15000000 http://www.house-of-code.org:1234/');
});
setTimeout(function () {
process.exit();
}, runTime * 1000);
setInterval(function () {
processed += 1;
console.log("process " + processed);
}, (runTime / 100) * 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment