forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow calling eventLoopUtilization() directly on a worker thread: const worker = new Worker('./foo.js'); const elu = worker.performance.eventLoopUtilization(); setTimeout(() => { worker.performance.eventLoopUtilization(elu); }, 10); Add a new performance object on the Worker instance that will hopefully one day hold all the other performance metrics, such as nodeTiming. Include benchmarks and tests. PR-URL: nodejs#35664 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: James M Snell <jasnell@gmail.com> Backport-PR-URL: nodejs#37165
- Loading branch information
1 parent
01c1a24
commit 5d57683
Showing
8 changed files
with
424 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const { Worker, parentPort } = require('worker_threads'); | ||
|
||
if (process.argv[2] === 'idle cats') { | ||
return parentPort.once('message', () => {}); | ||
} | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
method: [ | ||
'ELU_simple', | ||
'ELU_passed', | ||
], | ||
}); | ||
|
||
function main({ method, n }) { | ||
switch (method) { | ||
case 'ELU_simple': | ||
benchELUSimple(n); | ||
break; | ||
case 'ELU_passed': | ||
benchELUPassed(n); | ||
break; | ||
default: | ||
throw new Error(`Unsupported method ${method}`); | ||
} | ||
} | ||
|
||
function benchELUSimple(n) { | ||
const worker = new Worker(__filename, { argv: ['idle cats'] }); | ||
|
||
spinUntilIdle(worker, () => { | ||
bench.start(); | ||
for (let i = 0; i < n; i++) | ||
worker.performance.eventLoopUtilization(); | ||
bench.end(n); | ||
worker.postMessage('bye'); | ||
}); | ||
} | ||
|
||
function benchELUPassed(n) { | ||
const worker = new Worker(__filename, { argv: ['idle cats'] }); | ||
|
||
spinUntilIdle(worker, () => { | ||
let elu = worker.performance.eventLoopUtilization(); | ||
bench.start(); | ||
for (let i = 0; i < n; i++) | ||
elu = worker.performance.eventLoopUtilization(elu); | ||
bench.end(n); | ||
worker.postMessage('bye'); | ||
}); | ||
} | ||
|
||
function spinUntilIdle(w, cb) { | ||
const t = w.performance.eventLoopUtilization(); | ||
if (t.idle + t.active > 0) | ||
return process.nextTick(cb); | ||
setTimeout(() => spinUntilIdle(w, cb), 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.