-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
worker_threads resource limits option not working with cluster module #41066
Comments
The primary process above runs with no A similar case can be observed without cluster module if // test.js
const { Worker, isMainThread } = require('worker_threads');
const v8 = require('v8');
if (isMainThread) {
new Worker(__filename, {
resourceLimits: { maxOldGenerationSizeMb: 200 }
});
}
const type = isMainThread ? 'main' : 'work';
console.log(`[${type}] limit: ${v8.getHeapStatistics().heap_size_limit}`); Output > node test-worker.js
[main] limit: 4345298944
[work] limit: 260046848
> NODE_OPTIONS=--max-old-space-size=512 node test.js
[main] limit: 587202560
[work] limit: 587202560 When Lines 5201 to 5207 in e64613d
|
This adds a new flag `--thread-max-old-space-size` (name completely provisional). This has two advantages over the existing `--max-old-space-size` flag: 1. It allows setting the old space size for the main thread and using `resourceLimits` for worker threads. Currently `resourceLimits` will be ignored when `--max-old-space-size` is set (see the attached issues). 2. It is implemented using V8's public API, rather than relying on V8's internal flags whose stability and functionality are not guaranteed. The downside is that there are now two flags which (in most cases) do the same thing, so it may cause some confusion. I also think that we should deprecate `--max-old-space-size`, since the semantics feel pretty error-prone, but that's a story for another day. Refs: nodejs#41066 Refs: nodejs#43991 Refs: nodejs#43992
This adds a new flag `--thread-max-old-space-size` (name completely provisional). This has two advantages over the existing `--max-old-space-size` flag: 1. It allows setting the old space size for the main thread and using `resourceLimits` for worker threads. Currently `resourceLimits` will be ignored when `--max-old-space-size` is set (see the attached issues). 2. It is implemented using V8's public API, rather than relying on V8's internal flags whose stability and functionality are not guaranteed. The downside is that there are now two flags which (in most cases) do the same thing, so it may cause some confusion. I also think that we should deprecate `--max-old-space-size`, since the semantics feel pretty error-prone, but that's a story for another day. Refs: nodejs#41066 Refs: nodejs#43991 Refs: nodejs#43992
This adds a new flag `--thread-max-old-space-size` (name completely provisional). This has two advantages over the existing `--max-old-space-size` flag: 1. It allows setting the old space size for the main thread and using `resourceLimits` for worker threads. Currently `resourceLimits` will be ignored when `--max-old-space-size` is set (see the attached issues). 2. It is implemented using V8's public API, rather than relying on V8's internal flags whose stability and functionality are not guaranteed. The downside is that there are now two flags which (in most cases) do the same thing, so it may cause some confusion. I also think that we should deprecate `--max-old-space-size`, since the semantics feel pretty error-prone, but that's a story for another day. Refs: nodejs#41066 Refs: nodejs#43991 Refs: nodejs#43992
This adds a new flag `--thread-max-old-space-size` (name completely provisional). This has two advantages over the existing `--max-old-space-size` flag: 1. It allows setting the old space size for the main thread and using `resourceLimits` for worker threads. Currently `resourceLimits` will be ignored when `--max-old-space-size` is set (see the attached issues). 2. It is implemented using V8's public API, rather than relying on V8's internal flags whose stability and functionality are not guaranteed. The downside is that there are now two flags which (in most cases) do the same thing, so it may cause some confusion. I also think that we should deprecate `--max-old-space-size`, since the semantics feel pretty error-prone, but that's a story for another day. Refs: nodejs#41066 Refs: nodejs#43991 Refs: nodejs#43992
This adds a new flag `--thread-max-old-space-size` (name completely provisional). This has two advantages over the existing `--max-old-space-size` flag: 1. It allows setting the old space size for the main thread and using `resourceLimits` for worker threads. Currently `resourceLimits` will be ignored when `--max-old-space-size` is set (see the attached issues). 2. It is implemented using V8's public API, rather than relying on V8's internal flags whose stability and functionality are not guaranteed. The downside is that there are now two flags which (in most cases) do the same thing, so it may cause some confusion. I also think that we should deprecate `--max-old-space-size`, since the semantics feel pretty error-prone, but that's a story for another day. Refs: nodejs#41066 Refs: nodejs#43991 Refs: nodejs#43992
This adds a new flag `--thread-max-old-space-size` (name completely provisional). This has two advantages over the existing `--max-old-space-size` flag: 1. It allows setting the old space size for the main thread and using `resourceLimits` for worker threads. Currently `resourceLimits` will be ignored when `--max-old-space-size` is set (see the attached issues). 2. It is implemented using V8's public API, rather than relying on V8's internal flags whose stability and functionality are not guaranteed. The downside is that there are now two flags which (in most cases) do the same thing, so it may cause some confusion. I also think that we should deprecate `--max-old-space-size`, since the semantics feel pretty error-prone, but that's a story for another day. Refs: nodejs#41066 Refs: nodejs#43991 Refs: nodejs#43992
Version
v17.2.0
Platform
20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
Subsystem
worker_threads
What steps will reproduce the bug?
index.mjs
worker.mjs
output:
How often does it reproduce? Is there a required condition?
Whenever I use
worker_threads
module with acluster
- worker resourceLimits option is ignored.What is the expected behavior?
Expected output:
What do you see instead?
Max old space heap size probably was inherited from parent process (cluster) and resource limits option was ignored.
Additional information
This behavior may cause the memory leak on the worker to be handled incorrectly. Worker process will be killed if old heap space reach cluster process limits, not options I've passed.
The text was updated successfully, but these errors were encountered: