0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-22 07:37:56 +01:00
nodejs/benchmark/http/cluster.js
Deokjin Kim ca096563e0
benchmark: use cluster.isPrimary instead of cluster.isMaster
`cluster.isMaster` was deprecated. So need to use `cluster.isPrimary`
for benchmark.

Refs: https://github.com/nodejs/node/pull/47981
PR-URL: https://github.com/nodejs/node/pull/48002
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-05-17 05:51:53 +00:00

45 lines
920 B
JavaScript

'use strict';
const common = require('../common.js');
const PORT = common.PORT;
const cluster = require('cluster');
let bench;
if (cluster.isPrimary) {
bench = common.createBenchmark(main, {
// Unicode confuses ab on os x.
type: ['bytes', 'buffer'],
len: [4, 1024, 102400],
c: [50, 500],
duration: 5,
});
} else {
const port = parseInt(process.env.PORT || PORT);
require('../fixtures/simple-http-server.js').listen(port);
}
function main({ type, len, c, duration }) {
process.env.PORT = PORT;
let 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,
duration,
}, () => {
w1.destroy();
w2.destroy();
});
});
});
}