node/benchmark/http/cluster.js
Ruben Bridgewater a52878c239
benchmark: (http) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-01-23 01:29:28 +01:00

42 lines
883 B
JavaScript

'use strict';
const common = require('../common.js');
const PORT = common.PORT;
const cluster = require('cluster');
if (cluster.isMaster) {
var bench = common.createBenchmark(main, {
// unicode confuses ab on os x.
type: ['bytes', 'buffer'],
len: [4, 1024, 102400],
c: [50, 500]
});
} else {
const port = parseInt(process.env.PORT || PORT);
require('../fixtures/simple-http-server.js').listen(port);
}
function main({ type, len, c }) {
process.env.PORT = PORT;
var workers = 0;
const w1 = cluster.fork();
const w2 = cluster.fork();
cluster.on('listening', function() {
workers++;
if (workers < 2)
return;
setTimeout(function() {
const path = `/${type}/${len}`;
bench.http({
path: path,
connections: c
}, function() {
w1.destroy();
w2.destroy();
});
}, 100);
});
}