node/benchmark/http/cluster.js
Bartosz Sosnowski b1bbc68fb1 benchmark: support for multiple http benchmarkers
This adds support for multiple HTTP benchmarkers. Adds autocannon
as the secondary benchmarker.

PR-URL: https://github.com/nodejs/node/pull/8140
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2016-08-31 17:49:26 +02:00

41 lines
805 B
JavaScript

'use strict';
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, 500]
});
} 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;
bench.http({
path: path,
connections: conf.c
}, function() {
w1.destroy();
w2.destroy();
});
}, 100);
});
}