Skip to content

Commit

Permalink
test: harden the tick sampling logic
Browse files Browse the repository at this point in the history
Under peculiar system load conditions, the profiler thread
does not get enough CPU slices to perform the sampling.
Improve the interaction between worker and parent thread
by performing a large disc read, which is a better blend of
CPU and I/O bound work, than earlier versions.
This produces x10 more samples than the existing one,
in 10 iterations, as opposed to 1024.

Also capture worker error situations to improve debugging

Refs: #26401 (comment)

PR-URL: #32190
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
HarshithaKP authored and addaleax committed Mar 30, 2020
1 parent 2ee684a commit 73fec7c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test/sequential/test-worker-prof.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const { spawnSync } = require('child_process');
// Refs: https://github.com/nodejs/node/issues/24016

if (process.argv[2] === 'child') {
const fs = require('fs');
let files = fs.readdirSync(tmpdir.path);
const plog = files.filter((name) => /\.log$/.test(name))[0];
if (plog === undefined) {
Expand All @@ -19,20 +20,20 @@ if (process.argv[2] === 'child') {
}
const pingpong = `
let counter = 0;
const fs = require('fs');
const { Worker, parentPort } = require('worker_threads');
parentPort.on('message', (m) => {
if (counter++ === 1024)
if (counter++ === 10)
process.exit(0);
parentPort.postMessage(
m.toString().split('').reverse().toString().replace(/,/g, ''));
fs.readFileSync(m.toString()).slice(0, 1024 * 1024));
});
`;

const { Worker } = require('worker_threads');
const data = 'x'.repeat(1024);
const w = new Worker(pingpong, { eval: true });
w.on('message', (m) => {
w.postMessage(m.toString().split('').reverse().toString().replace(/,/g, ''));
w.postMessage(process.execPath);
});

w.on('exit', common.mustCall(() => {
Expand All @@ -45,7 +46,7 @@ if (process.argv[2] === 'child') {
}
process.exit(0);
}));
w.postMessage(data);
w.postMessage(process.execPath);
} else {
tmpdir.refresh();
const spawnResult = spawnSync(
Expand Down

0 comments on commit 73fec7c

Please sign in to comment.