Skip to content

Commit 2b79052

Browse files
jbergstroemrvagg
authored andcommitted
benchmark: check for wrk ahead of running benchmarks
PR-URL: #982 Reviewed-By: Rod Vagg <[email protected]>
1 parent a45d4f8 commit 2b79052

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pkgsrc: $(PKGSRC)
331331
haswrk=$(shell which wrk > /dev/null 2>&1; echo $$?)
332332
wrk:
333333
ifneq ($(haswrk), 0)
334-
@echo "please install wrk before proceeding"; >&2
334+
@echo "please install wrk before proceeding. More information can be found in benchmark/README.md." >&2
335335
@exit 1
336336
endif
337337

benchmark/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
This folder contains benchmark tests to measure the performance for certain
44
io.js APIs.
55

6-
## prerequisites
6+
## Prerequisites
77

8-
Most of the http benchmarks require `wrk` and `ab` being installed.
8+
Most of the http benchmarks require [`wrk`][wrk] and [`ab`][ab] being installed.
9+
These are most often available through your preferred package manager.
10+
11+
[wrk]: https://github.com/wg/wrk
12+
[ab]: http://httpd.apache.org/docs/2.2/programs/ab.html
913

1014
## How to run tests
1115

benchmark/common.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
var assert = require('assert');
22
var fs = require('fs');
33
var path = require('path');
4-
var spawn = require('child_process').spawn;
4+
var child_process = require('child_process');
55

66
var silent = +process.env.NODE_BENCH_SILENT;
77

88
exports.PORT = process.env.PORT || 12346;
99

1010
// If this is the main module, then run the benchmarks
1111
if (module === require.main) {
12+
hasWrk();
1213
var type = process.argv[2];
1314
var testFilter = process.argv[3];
1415
if (!type) {
@@ -36,6 +37,15 @@ if (module === require.main) {
3637
runBenchmarks();
3738
}
3839

40+
function hasWrk() {
41+
var result = child_process.spawnSync('wrk', ['-h']);
42+
if (result.error.code === 'ENOENT') {
43+
console.error('Couldn\'t locate `wrk` which is needed for running ' +
44+
'benchmarks. Check benchmark/README.md for further instructions.');
45+
process.exit(-1);
46+
}
47+
}
48+
3949
function runBenchmarks() {
4050
var test = tests.shift();
4151
if (!test)
@@ -48,7 +58,7 @@ function runBenchmarks() {
4858
test = path.resolve(dir, test);
4959

5060
var a = (process.execArgv || []).concat(test);
51-
var child = spawn(process.execPath, a, { stdio: 'inherit' });
61+
var child = child_process.spawn(process.execPath, a, { stdio: 'inherit' });
5262
child.on('close', function(code) {
5363
if (code) {
5464
process.exit(code);
@@ -70,7 +80,10 @@ function Benchmark(fn, options) {
7080
this._name = require.main.filename.split(/benchmark[\/\\]/).pop();
7181
this._start = [0,0];
7282
this._started = false;
83+
7384
var self = this;
85+
86+
hasWrk();
7487
process.nextTick(function() {
7588
self._run();
7689
});
@@ -85,7 +98,7 @@ Benchmark.prototype.http = function(p, args, cb) {
8598
args = args.concat(url);
8699

87100
var out = '';
88-
var child = spawn('wrk', args);
101+
var child = child_process.spawn('wrk', args);
89102

90103
child.stdout.setEncoding('utf8');
91104

@@ -145,7 +158,7 @@ Benchmark.prototype._run = function() {
145158
if (!argv)
146159
return;
147160
argv = process.execArgv.concat(argv);
148-
var child = spawn(node, argv, { stdio: 'inherit' });
161+
var child = child_process.spawn(node, argv, { stdio: 'inherit' });
149162
child.on('close', function(code, signal) {
150163
if (code)
151164
console.error('child process exited with code ' + code);

0 commit comments

Comments
 (0)