Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

bench: Use wrk for http benchmarking

  • Loading branch information...
commit 74e8bdef2a8f8327847bca0200904924795edf4c 1 parent bcda807
Isaac Z. Schlueter authored
19 benchmark/common.js
@@ -11,7 +11,6 @@ if (module === require.main) {
11 11 process.exit(1);
12 12 }
13 13
14   - var path = require('path');
15 14 var fs = require('fs');
16 15 var dir = path.join(__dirname, type);
17 16 var tests = fs.readdirSync(dir);
@@ -59,16 +58,16 @@ function Benchmark(fn, options) {
59 58 });
60 59 }
61 60
62   -// run ab against a server.
63   -Benchmark.prototype.ab = function(path, args, cb) {
64   - var url = 'http://127.0.0.1:' + exports.PORT + path;
  61 +// benchmark an http server.
  62 +Benchmark.prototype.http = function(p, args, cb) {
  63 + var url = 'http://127.0.0.1:' + exports.PORT + p;
65 64 args.push(url);
66 65
67 66 var self = this;
68 67 var out = '';
69 68 var spawn = require('child_process').spawn;
70   - // console.error('ab %s', args.join(' '));
71   - var child = spawn('ab', args);
  69 + var wrk = path.resolve(__dirname, '..', 'tools', 'wrk', 'wrk');
  70 + var child = spawn(wrk, args);
72 71
73 72 child.stdout.setEncoding('utf8');
74 73
@@ -81,14 +80,14 @@ Benchmark.prototype.ab = function(path, args, cb) {
81 80 cb(code);
82 81
83 82 if (code) {
84   - console.error('ab failed with ' + code);
  83 + console.error('wrk failed with ' + code);
85 84 process.exit(code)
86 85 }
87   - var m = out.match(/Requests per second: +([0-9\.]+)/);
  86 + var m = out.match(/Requests\/sec:[ \t]+([0-9\.]+)/);
88 87 var qps = m && +m[1];
89 88 if (!qps) {
90   - process.stderr.write(out + '\n');
91   - console.error('ab produced strange output');
  89 + console.error('%j', out);
  90 + console.error('wrk produced strange output');
92 91 process.exit(1);
93 92 }
94 93 self.report(+qps);
7 benchmark/http/cluster.js
@@ -7,7 +7,7 @@ if (cluster.isMaster) {
7 7 // unicode confuses ab on os x.
8 8 type: ['bytes', 'buffer'],
9 9 length: [4, 1024, 102400],
10   - c: [50, 150]
  10 + c: [50, 500]
11 11 });
12 12 } else {
13 13 require('../http_simple.js');
@@ -27,11 +27,12 @@ function main(conf) {
27 27 setTimeout(function() {
28 28 var path = '/' + conf.type + '/' + conf.length;
29 29 var args = ['-r', '-t', 5, '-c', conf.c, '-k'];
  30 + var args = ['-r', 5000, '-t', 8, '-c', conf.c];
30 31
31   - bench.ab(path, args, function() {
  32 + bench.http(path, args, function() {
32 33 w1.destroy();
33 34 w2.destroy();
34 35 });
35   - }, 2000);
  36 + }, 100);
36 37 });
37 38 }
11 benchmark/http/http_simple.js
@@ -5,7 +5,7 @@ var bench = common.createBenchmark(main, {
5 5 // unicode confuses ab on os x.
6 6 type: ['bytes', 'buffer'],
7 7 length: [4, 1024, 102400],
8   - c: [50, 150]
  8 + c: [50, 500]
9 9 });
10 10
11 11 function main(conf) {
@@ -15,14 +15,9 @@ function main(conf) {
15 15 var server = spawn(process.execPath, [simple]);
16 16 setTimeout(function() {
17 17 var path = '/' + conf.type + '/' + conf.length; //+ '/' + conf.chunks;
18   - var args = ['-r', '-t', 5];
  18 + var args = ['-r', 5000, '-t', 8, '-c', conf.c];
19 19
20   - if (+conf.c !== 1)
21   - args.push('-c', conf.c);
22   -
23   - args.push('-k');
24   -
25   - bench.ab(path, args, function() {
  20 + bench.http(path, args, function() {
26 21 server.kill();
27 22 });
28 23 }, 2000);

0 comments on commit 74e8bde

Please sign in to comment.
Something went wrong with that request. Please try again.