Perfect your code
With built-in code review tools, GitHub makes it easy to raise the quality bar before you ship. Join the 40 million developers who've merged over 200 million pull requests.
Sign up for free See pricing for teams and enterprisesworker: allow specifying resource limits #26628
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
What happens if the worker itself starts a new worker? |
|
LGTM though I have some questions |
| Null(env()->isolate()).As<Value>(), | ||
| }; | ||
|
|
||
| MakeCallback(env()->onexit_string(), arraysize(args), args); |
This comment has been minimized.
This comment has been minimized.
joyeecheung
Mar 13, 2019
Member
Maybe we can pass the limits back here as well to display them in the error messages?
This comment has been minimized.
This comment has been minimized.
addaleax
Mar 13, 2019
Author
Member
Do you have suggestions for how/when to pass them back? I don’t think you’re thinking about callback arguments, right?
This comment has been minimized.
This comment has been minimized.
joyeecheung
Mar 13, 2019
Member
If we have those as AliasedBuffers we could pass them back here right? (Or is that not guaranteed to be valid at this point?)
This comment has been minimized.
This comment has been minimized.
|
In case you missed it, I'll ask again: What happens if the worker itself starts a new worker? |
This comment has been minimized.
This comment has been minimized.
|
@targos - by looking at the current design, I guess:
yes, through this interface
yes
no |
This comment has been minimized.
This comment has been minimized.
|
Definitely like the direction on this. And I like the way the failure condition is handled. The one thing that's missing is: how would a worker know what it's limits are without (as you do in the tests) passing those in out of band. |
This comment has been minimized.
This comment has been minimized.
YurySolovyov
commented
Mar 13, 2019
|
Any way to limit CPU usage? |
This comment has been minimized.
This comment has been minimized.
|
@jasnell @joyeecheung I guess we could make the resource limits available on the In that case the main question for me would be, is there anything we could/should do for non-Worker threads? Should we just (inaccurately) report @targos Yeah, the options are independent for each Worker, in the way that @gireeshpunathil explained.
@YurySolovyov Not in this PR, sorry. That might also be pretty complex to implement, because we don’t have the VM available to do this for us. |
This comment has been minimized.
This comment has been minimized.
|
How does the diagnostic report work wrt. workers? Are the resource limits being added here something that could be added to the report? |
This comment has been minimized.
This comment has been minimized.
|
@richardlau The diagnostic report is clueless about Workers (see also #26293). But yes, when they add support, I think it makes sense to include the data. |
- see nodejs/node#26628
preparing for: nodejs/node#26628 (comment)
This comment has been minimized.
This comment has been minimized.
|
@addaleax seems like this requires a rebase. |
This comment has been minimized.
This comment has been minimized.
|
@jasnell @joyeecheung Before I rebase this … any thoughts on #26628 (comment)? |
This comment has been minimized.
This comment has been minimized.
I would go with not providing the object at all. It's easier to start small and known limitations are better than..known bugs? |
This comment has been minimized.
This comment has been minimized.
|
I'm cleaning out a few old PRs 🧹. I'm closing this due to inactivity. Please re-open if needed! |
This comment has been minimized.
This comment has been minimized.
|
I don't really see any reason why this could not have landed, don't see any blockers. On the other hand, I find great value for this PR as it provides fine grained control over the worker's execution environment - something that can be leveraged in workloads that means a lot (such as cloud) pinging @addaleax to see if I missed something. |
8b01037
to
6fe4678
This comment has been minimized.
This comment has been minimized.
|
@joyeecheung @gireeshpunathil I’ve rebased this and made the resource constraints available as an object on both the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
still LGTM |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@addaleax sure :) |
This comment has been minimized.
This comment has been minimized.
|
I am scared people won't understand what the limits... limit but the code looks good to me and this is genuinely useful. |
| @@ -294,10 +311,35 @@ function pipeWithoutWarning(source, dest) { | |||
| dest._maxListeners = destMaxListeners; | |||
| } | |||
|
|
|||
| const resourceLimitsArray = new Float64Array(kTotalResourceLimitCount); | |||
This comment has been minimized.
This comment has been minimized.
joyeecheung
Nov 3, 2019
Member
Is there a reason not to reuse resourceLimitsRaw here?
Although if we expose makeResourceLimits from this file and calculate the publicly exposed resourceLimits from lib/worker_threads.js instead it makes more sense to use two arrays in case someone created a worker internally with a resource limit..somehow.
This comment has been minimized.
This comment has been minimized.
addaleax
Nov 4, 2019
Author
Member
Practically speaking, yes, the reason is that resourceLimitsRaw is currently not defined in the main thread. And given that this is a very small typed array, I’m okay with that. If you’re concerned about the extra resource usage, I’d probably prefer changing this to not be a static variable and instead generate one for each call to parseResourceLimits()?
|
LGTM (the comment above was a nit) |
| &loop_, | ||
| w->platform_); | ||
| CHECK_NOT_NULL(isolate); | ||
| Isolate::CreateParams params; |
This comment has been minimized.
This comment has been minimized.
joyeecheung
Nov 3, 2019
Member
For my own understanding...WorkerThreadData is actually closer to NodeMainInstance for the main thread even though we don't have an equivalent abstraction of Worker for the main thread at the moment? (This was my impression when I tried with #29925 locally but I decided to take some more time to figure out a proper class hierarchy before moving forward..)
I wonder whether it makes sense to have Environment points to a base class of Worker and MainThread (?) if they have a longer life time than Environment.
This comment has been minimized.
This comment has been minimized.
addaleax
Nov 4, 2019
Author
Member
For my own understanding...
WorkerThreadDatais actually closer toNodeMainInstancefor the main thread even though we don't have an equivalent abstraction ofWorkerfor the main thread at the moment? (This was my impression when I tried with #29925 locally but I decided to take some more time to figure out a proper class hierarchy before moving forward..)
It is somewhat similar, yes.
I wonder whether it makes sense to have
Environmentpoints to a base class ofWorkerandMainThread(?) if they have a longer life time thanEnvironment.
What would we use that for? And how would that fit into the embedder API? Both Workers and the main thread have a lifetime longer than the Environment, but only very slightly so…
This comment has been minimized.
This comment has been minimized.
joyeecheung
Nov 4, 2019
Member
For example, Worker, NodeMainInstance and Environment all keep copies of arguments and exec arguments. We could reduce the duplication by only keeping them in Worker and MainThread. There seem to be a lot of duplication along the hierarchy at the moment..
This comment has been minimized.
This comment has been minimized.
addaleax
Nov 5, 2019
Author
Member
I would be careful about that… deduplication is nice but right now moving towards a better embedder API is my primary goal, and linking from Environment to a superclass of Worker and NodeMainInstance sounds a bit fragile
This comment has been minimized.
This comment has been minimized.
joyeecheung
Nov 5, 2019
Member
If anything...I think a public version of that super class could be a good base for a newer set of better embedder APIs? (but maybe it's just a crazy idea, I have not given too much thought into it).
This comment has been minimized.
This comment has been minimized.
Allow specifying resource limits for the JS engine instance created as part of a Worker. PR-URL: #26628 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This comment has been minimized.
This comment has been minimized.
|
Landed in d855904 |
Allow specifying resource limits for the JS engine instance created as part of a Worker. PR-URL: #26628 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update V8 to 7.9
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update V8 to 7.9
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update V8 to 7.9
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update V8 to 7.9
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) nodejs#30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
nodejs#30162
* deps:
* Update V8 to 7.9
* Update `npm` to 6.13.0 (Ruy Adorno)
nodejs#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
nodejs#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
nodejs#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
nodejs#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
nodejs#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
nodejs#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
nodejs#30234
PR-URL: nodejs#30547
Notable changes:
* addons:
* Deprecate one- and two-argument `AtExit()`. Use the three-argument
variant of `AtExit()` or `AddEnvironmentCleanupHook()` instead
(Anna Henningsen) #30227
* child_process,cluster:
* The `serialization` option is added that allows child process
IPC to use the V8 serialization API (to e.g., pass through data
types like sets or maps) (Anna Henningsen)
#30162
* deps:
* Update V8 to 7.9
* Update `npm` to 6.13.0 (Ruy Adorno)
#30271
* embedder:
* Exposes the ability to pass cli flags / options through an API
as embedder (Shelley Vohr)
#30466
* Allow adding linked bindings to Environment (Anna Henningsen)
#30274
* esm:
* Unflag --experimental-modules (Guy Bedford)
#29866
* stream:
* Add `writable.writableCorked` property (Robert Nagy)
#29012
* worker:
* Allow specifying resource limits (Anna Henningsen)
#26628
* v8:
* The Serialization API is now stable (Anna Henningsen)
#30234
PR-URL: #30547
addaleax commentedMar 13, 2019
Allow specifying resource limits for the JS engine instance created as part of a Worker.
/cc @nodejs/workers
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes