-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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: add flag to control old space size #43995
base: main
Are you sure you want to change the base?
Conversation
c633fdb
to
a08fc49
Compare
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
I think we should strive for a uniform approach across all worker limits here. IIRC from #43630, the stack size is also vastly inconsistent: the main thread has a reserved stack size (which is usually around 8 MiB, except on Windows, which is what #43630 is about), and then a small part of that is used as the V8 stack size of the main application thread (less than 1 MiB). Worker threads, however, do not seem to inherit either, and the 4 MiB default limit seems to be the reserved stack size of the thread and also the V8 stack size of the worker thread. |
I did not know that about
Could you elaborate more on this? What does a "uniform approach" entail? Are you just suggesting we add the other three relevant flags, or something else? |
What I mean is: the mechanism through which resource limits for workers are determined should be the same for all resource limits (unless there is a good reason to have different mechanisms).
I am not sure if adding command line flags is the right approach at all. I believe @addaleax might have more insight here. |
Not sure what I can add to the conversation here – I would definitely shy away from adding command line flags (process-level config) for controlling worker thread behavior (thread-level config). Regarding the stack size, I don’t remember all the original context but stack size limits for threads definitely vary quite a bit, and iirc some platforms had significantly lower stack limits for spawned threads than for the main thread, making it difficult to use Worker threads there (and to tell V8 about the correct stack size, which is just as relevant). |
Sorry, I think there's some confusion because I poorly named the flag here. What I'm proposing (& what this diff adds) is essentially |
Ah yeah – the option should be named and described differently then, I would say :) |
I will try to come up with a better name (so far I am leaning towards something like Hopefully with my clarification the need for some sort of further knob is pretty clear: setting the max old space size today means overriding all I think there's still a question of how exactly the new flag should interact with
My inclination is to proceed with (1), because both (2) and (3) can be implemented by the user anyway. |
This adds a new flag
--thread-max-old-space-size
(name completelyprovisional). This flag lets the user configure the size of the main
thread's old space size. This has two advantages over the existing
--max-old-space-size
flag:resourceLimits
for worker threads. CurrentlyresourceLimits
willbe ignored when
--max-old-space-size
is set (see the attachedissues).
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 prettyerror-prone, but that's a story for another day.
Refs: #41066
Refs: #43991
Refs: #43992