summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-02-11 23:43:22 -0800
committerisaacs <i@izs.me>2013-02-19 14:14:31 -0800
commit536ce446898f3b788d7f0134de8397db55161b07 (patch)
tree1f21c37cbc830a1c3e9f12b1eee6adefc66c4f49 /benchmark
parentd5d04a51d641cca321e8470a64e84dd8b7a97e4a (diff)
downloadnode-new-536ce446898f3b788d7f0134de8397db55161b07.tar.gz
bench: http benchmarks
Also: make http_simple less chatty
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/http/cluster.js37
-rw-r--r--benchmark/http/http_simple.js29
-rw-r--r--benchmark/http_simple.js14
3 files changed, 69 insertions, 11 deletions
diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js
new file mode 100644
index 0000000000..a8c7abe689
--- /dev/null
+++ b/benchmark/http/cluster.js
@@ -0,0 +1,37 @@
+var common = require('../common.js');
+var PORT = common.PORT;
+
+var cluster = require('cluster');
+if (cluster.isMaster) {
+ var bench = common.createBenchmark(main, {
+ // unicode confuses ab on os x.
+ type: ['bytes', 'buffer'],
+ length: [4, 1024, 102400],
+ c: [50, 150]
+ });
+} else {
+ require('../http_simple.js');
+}
+
+function main(conf) {
+ process.env.PORT = PORT;
+ var workers = 0;
+ var w1 = cluster.fork();
+ var w2 = cluster.fork();
+
+ cluster.on('listening', function() {
+ workers++;
+ if (workers < 2)
+ return;
+
+ setTimeout(function() {
+ var path = '/' + conf.type + '/' + conf.length;
+ var args = ['-r', '-t', 5, '-c', conf.c, '-k'];
+
+ bench.ab(path, args, function() {
+ w1.destroy();
+ w2.destroy();
+ });
+ }, 2000);
+ });
+}
diff --git a/benchmark/http/http_simple.js b/benchmark/http/http_simple.js
new file mode 100644
index 0000000000..2cef41f46f
--- /dev/null
+++ b/benchmark/http/http_simple.js
@@ -0,0 +1,29 @@
+var common = require('../common.js');
+var PORT = common.PORT;
+
+var bench = common.createBenchmark(main, {
+ // unicode confuses ab on os x.
+ type: ['bytes', 'buffer'],
+ length: [4, 1024, 102400],
+ c: [50, 150]
+});
+
+function main(conf) {
+ process.env.PORT = PORT;
+ var spawn = require('child_process').spawn;
+ var simple = require('path').resolve(__dirname, '../http_simple.js');
+ var server = spawn(process.execPath, [simple]);
+ setTimeout(function() {
+ var path = '/' + conf.type + '/' + conf.length; //+ '/' + conf.chunks;
+ var args = ['-r', '-t', 5];
+
+ if (+conf.c !== 1)
+ args.push('-c', conf.c);
+
+ args.push('-k');
+
+ bench.ab(path, args, function() {
+ server.kill();
+ });
+ }, 2000);
+}
diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js
index 236b046e92..54500b49b5 100644
--- a/benchmark/http_simple.js
+++ b/benchmark/http_simple.js
@@ -4,8 +4,6 @@ var path = require('path'),
var port = parseInt(process.env.PORT || 8000);
-console.log('pid ' + process.pid);
-
var fixed = makeString(20 * 1024, 'C'),
storedBytes = {},
storedBuffer = {},
@@ -18,7 +16,7 @@ if (useDomains) {
var domain = require('domain');
var gdom = domain.create();
gdom.on('error', function(er) {
- console.log('Error on global domain', er);
+ console.error('Error on global domain', er);
throw er;
});
gdom.enter();
@@ -43,7 +41,6 @@ var server = http.createServer(function (req, res) {
if (n <= 0)
throw new Error('bytes called with n <= 0')
if (storedBytes[n] === undefined) {
- console.log('create storedBytes[n]');
storedBytes[n] = makeString(n, 'C');
}
body = storedBytes[n];
@@ -53,7 +50,6 @@ var server = http.createServer(function (req, res) {
if (n <= 0)
throw new Error('buffer called with n <= 0');
if (storedBuffer[n] === undefined) {
- console.log('create storedBuffer[n]');
storedBuffer[n] = new Buffer(n);
for (var i = 0; i < n; i++) {
storedBuffer[n][i] = 'C'.charCodeAt(0);
@@ -66,7 +62,6 @@ var server = http.createServer(function (req, res) {
if (n <= 0)
throw new Error('unicode called with n <= 0');
if (storedUnicode[n] === undefined) {
- console.log('create storedUnicode[n]');
storedUnicode[n] = makeString(n, '\u263A');
}
body = storedUnicode[n];
@@ -120,9 +115,6 @@ function makeString(size, c) {
}
server.listen(port, function () {
- console.log('Listening at http://127.0.0.1:'+port+'/');
-});
-
-process.on('exit', function() {
- console.error('libuv counters', process.uvCounters());
+ if (module === require.main)
+ console.error('Listening at http://127.0.0.1:'+port+'/');
});