0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/http/cluster.js
Roman Reiss 55b80f9029
tools: enable block-scoped-var eslint rule
PR-URL: https://github.com/nodejs/node/pull/27616
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-05-10 16:58:49 +02:00

43 lines
872 B
JavaScript

'use strict';
const common = require('../common.js');
const PORT = common.PORT;
const cluster = require('cluster');
let bench;
if (cluster.isMaster) {
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', () => {
workers++;
if (workers < 2)
return;
setImmediate(() => {
const path = `/${type}/${len}`;
bench.http({
path: path,
connections: c
}, () => {
w1.destroy();
w2.destroy();
});
});
});
}