From fce36cf554d825c072515398855abcc4ec98b982 Mon Sep 17 00:00:00 2001 From: Harshitha KP Date: Wed, 11 Mar 2020 01:41:54 -0400 Subject: [PATCH 1/3] test: harden the tick sampling logic 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: https://github.com/nodejs/node/issues/26401#issuecomment-597438516 --- test/sequential/test-worker-prof.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/test/sequential/test-worker-prof.js b/test/sequential/test-worker-prof.js index 80596a76f94f66..4919aa2496ff42 100644 --- a/test/sequential/test-worker-prof.js +++ b/test/sequential/test-worker-prof.js @@ -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) { @@ -19,20 +20,25 @@ 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()).toString()); }); `; 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('error', (e) => { + console.error(`worker exited with error: ${e}`); + process.exit(1); }); w.on('exit', common.mustCall(() => { @@ -45,7 +51,7 @@ if (process.argv[2] === 'child') { } process.exit(0); })); - w.postMessage(data); + w.postMessage(process.execPath); } else { tmpdir.refresh(); const spawnResult = spawnSync( From 417f5a308e0ad76b6e008df8c08329b90f19b8d0 Mon Sep 17 00:00:00 2001 From: Harshitha K P Date: Fri, 13 Mar 2020 15:14:06 +0530 Subject: [PATCH 2/3] fixup: address review comment --- test/sequential/test-worker-prof.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/sequential/test-worker-prof.js b/test/sequential/test-worker-prof.js index 4919aa2496ff42..b18dd942197f1b 100644 --- a/test/sequential/test-worker-prof.js +++ b/test/sequential/test-worker-prof.js @@ -36,11 +36,6 @@ if (process.argv[2] === 'child') { w.postMessage(process.execPath); }); - w.on('error', (e) => { - console.error(`worker exited with error: ${e}`); - process.exit(1); - }); - w.on('exit', common.mustCall(() => { files = fs.readdirSync(tmpdir.path); const wlog = files.filter((name) => /\.log$/.test(name) && name !== plog)[0]; From d9b54c0b35c62a57ee0b176046ce5029335296ca Mon Sep 17 00:00:00 2001 From: Harshitha K P Date: Sat, 14 Mar 2020 11:13:32 +0530 Subject: [PATCH 3/3] fixup: address review comment --- test/sequential/test-worker-prof.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/sequential/test-worker-prof.js b/test/sequential/test-worker-prof.js index b18dd942197f1b..f89ff962ff785d 100644 --- a/test/sequential/test-worker-prof.js +++ b/test/sequential/test-worker-prof.js @@ -26,7 +26,7 @@ if (process.argv[2] === 'child') { if (counter++ === 10) process.exit(0); parentPort.postMessage( - fs.readFileSync(m.toString()).toString()); + fs.readFileSync(m.toString()).slice(0, 1024 * 1024)); }); `;