0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/http/cluster.js
Anatoli Papirovski 957532ec61
test: fix long-running http benchmarks
PR-URL: https://github.com/nodejs/node/pull/20125
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2018-04-22 11:06:36 +02:00

42 lines
880 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;
setImmediate(function() {
const path = `/${type}/${len}`;
bench.http({
path: path,
connections: c
}, function() {
w1.destroy();
w2.destroy();
});
});
});
}