mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Having an experimental feature behind a flag makes change if we are expecting significant breaking changes to its API. Since the Worker API has been essentially stable since its initial introduction, and no noticeable doubt about possibly not keeping the feature around has been voiced, removing the flag and thereby reducing the barrier to experimentation, and consequently receiving feedback on the implementation, seems like a good idea. PR-URL: https://github.com/nodejs/node/pull/25361 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
77 lines
1.7 KiB
JavaScript
77 lines
1.7 KiB
JavaScript
'use strict';
|
|
const common = require('../common.js');
|
|
const { spawn } = require('child_process');
|
|
const path = require('path');
|
|
|
|
let Worker; // Lazy loaded in main
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
dur: [1],
|
|
script: ['benchmark/fixtures/require-cachable', 'test/fixtures/semicolon'],
|
|
mode: ['process', 'worker']
|
|
}, {
|
|
flags: ['--expose-internals']
|
|
});
|
|
|
|
function spawnProcess(script) {
|
|
const cmd = process.execPath || process.argv[0];
|
|
const argv = ['--expose-internals', script];
|
|
return spawn(cmd, argv);
|
|
}
|
|
|
|
function spawnWorker(script) {
|
|
return new Worker(script, { stderr: true, stdout: true });
|
|
}
|
|
|
|
function start(state, script, bench, getNode) {
|
|
const node = getNode(script);
|
|
let stdout = '';
|
|
let stderr = '';
|
|
|
|
node.stdout.on('data', (data) => {
|
|
stdout += data;
|
|
});
|
|
|
|
node.stderr.on('data', (data) => {
|
|
stderr += data;
|
|
});
|
|
|
|
node.on('exit', (code) => {
|
|
if (code !== 0) {
|
|
console.error('------ stdout ------');
|
|
console.error(stdout);
|
|
console.error('------ stderr ------');
|
|
console.error(stderr);
|
|
throw new Error(`Error during node startup, exit code ${code}`);
|
|
}
|
|
state.throughput++;
|
|
|
|
if (state.go) {
|
|
start(state, script, bench, getNode);
|
|
} else {
|
|
bench.end(state.throughput);
|
|
}
|
|
});
|
|
}
|
|
|
|
function main({ dur, script, mode }) {
|
|
const state = {
|
|
go: true,
|
|
throughput: 0
|
|
};
|
|
|
|
setTimeout(function() {
|
|
state.go = false;
|
|
}, dur * 1000);
|
|
|
|
script = path.resolve(__dirname, '../../', `${script}.js`);
|
|
if (mode === 'worker') {
|
|
Worker = require('worker_threads').Worker;
|
|
bench.start();
|
|
start(state, script, bench, spawnWorker);
|
|
} else {
|
|
bench.start();
|
|
start(state, script, bench, spawnProcess);
|
|
}
|
|
}
|