GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — workers: implement --max-worker-threads command line option by jasnell · Pull Request #32606 · nodejs/node Conversation
Member
There are two commits here:
From the second commit message: /cc @addaleax Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
jasnell
force-pushed
the
max-worker-count
branch
from
b851f4c to
1d2c945
Compare
jasnell
force-pushed
the
max-worker-count
branch
from
1d2c945 to
d1e4236
Compare
addaleax
reviewed
Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
addaleax
reviewed
Uh oh!
There was an error while loading. Please reload this page.
addaleax
reviewed
Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
jasnell
force-pushed
the
max-worker-count
branch
from
495f2a0 to
cc4bfab
Compare
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
addaleax
approved these changes
Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
addaleax
approved these changes
Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
jasnell
force-pushed
the
max-worker-count
branch
from
1ce6f54 to
1327c0f
Compare
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. Utility helper that makes working with uv_cpu_info easier Signed-off-by: James M Snell <[email protected]> Creating too many active worker threads at one time can lead to significant performance degradation of the entire Node.js process. This adds a worker thread counter that will cause a warning to be emitted if exceeded. Workers can still be created beyond the limit, however. The warning is similar in spirit to the too many event handlers warning emitted by EventEmitter. By default, the limit is one less than four times the total number of CPUs available calculated at system start. The `--max-worker-threads` command-line option can be set to set a non-default value. The option is permitted in `NODE_OPTIONS` and must be positive number greater than zero. The counter and the option are per-process in order to account for Workers that create their own Workers. The warning will be emitted once each time the limit is exceeded, so may be emitted more than once per process. That is, if the limit is 2, and 5 workers are created, only a single warning will be emitted. If the number of active workers falls back below 2 and is subsequently exceeded again, the warning will be emitted again. Signed-off-by: James M Snell <[email protected]>
jasnell
force-pushed
the
max-worker-count
branch
from
29bc7cb to
2c99cd5
Compare
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
benjamingr
approved these changes
Member
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
lundibundi
approved these changes
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely +1 on the idea but I agree that the default should be Also, perhaps we can name this something "weaker" than "max-worker-threads" as for me the name implies that we won't be able to create more than the specified amount of workers and not that we will just get a warning about it?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Comment on lines
+94
to
+95
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think we usually try to put empty lines in between methods. Could you also run
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sigh... Yeah, when I update this I'll switch over to the linux box and tweak the formatting.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: (here and below)
Suggested change
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: simplification and a bit fewer promises (and same applies to the other test if you decide to change) function makeWorker() { return new Promise((res) => { const worker = new Worker(expr, { eval: true }); worker.once('online', () => res(worker)); }); } async function doTest() { const promises = []; for (let n = 0; n < cpu_count; n++) promises.push(makeWorker()); return Promise.all(promises) .then((workers) => workers.forEach((i) => i.terminate()) }
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do that, then I’d go one step further and use async function makeWorker() { const worker = new Worker(expr, { eval: true }); await once(worker, 'online'); return worker; } 🙂
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
There was an error while loading. Please reload this page.
|
All, I'm going to take this a slightly different direction. As I mentioned above, the intent here is largely to improve process-wide visibility of the number of workers that are being created since, currently, they are only visible to the immediate parent thread that created them. Instead of emitting a warning, here's what I'm thinking: Via the perf_hooks API, introduce a new The tracker takes it's design inspiration from async hooks. However, unlike async hooks, it is not limited to reporting on only the handles associated with the threads event loop. const { WorkerHook } = require('perf_hooks'); const hook = new WorkerHook({ init(id, parent_id, handled) { console.log(`Worker ${id} created by thread ${parent_id}.`); // handled is described below... }, destroy(id, parent_id, handled) { console.log(`Worker ${id} destroyed`); } }); hook.enable(); // Atomically get the number of workers process-wide without creating a hook console.log(WorkerHook.processWorkerCount); Let's say that Main Thread creates The
const hook = WorkerHook({ init(id, parent_id, handled) { /** handled will be false **/ } }); hook.enable() Main Thread: const hook = WorkerHook({ init(id, parent_id, handled) { /** handled will be true **/ } }); hook.enable() However... if disable the If multiple The API here serves two key goals:
Several discussion points:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Closing this until I can get back to it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.