-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
src: use thread defaults provided by v8::platform #4243
Conversation
By passing `const int thread_pool_size = 0` to `CreateDefaultPlatform` we allow v8 to choose sensible defaults based on the currently online processors.
I have no real opinion on whether this is better or worse but for background, the reason I chose 4 is that:
(4 + 4 technically actually overcommits because of the main thread but a little overcommit seems like a decent trade-off vs. under-utilization.) One glorious day we'll be able to service libuv and V8 from a single thread pool but until then, we need to strike a balance that doesn't starve one or the other. Aside, the way to benchmark this is to:
Those combined will overload both thread pools to the point that they need to queue up work items and then it's a matter of measuring throughput and latency. Aside aside, as a stop-gap measure we could tweak node to divide the cores between the two thread pools at start-up. |
How aggressive is V8 at consuming the available cores when the default is set to 0? I definitely think that we should look at benchmarking this more before making changes here. |
It varies. V8 allocates up to three threads for concurrent sweeping; any remaining threads are used for concurrent recompilation and on-stack replacement. It depends on the performance profile of the application whether those threads have work to do. |
Would it be possible / desirable to run benchmarks across machines with variable numbers of cores and use that to determine a more algorithmic way of determining the reasonable defaults? |
Here's one idea: rather than guessing at this, perhaps add a CLI flag to allow the default to be overridden? e.g. |
Sounds like a good idea, however I don’t like having undocumented features. Another approach could be to have an |
That's certainly a possibility but not sure it's ideal until we have more than one flag that would fall under that kind of category. Adding it to the |
Ok, I am working on this at the moment. |
Based on the conversation in nodejs#4243 this implements a way to increase and decrease the size of the thread pool used in v8. Currently v8 restricts the thread pool size to `kMaxThreadPoolSize` which at this commit is (4). So it is only possible to decrease the thread pool size at the time of this commit. However with changes upstream this could change at a later date. If set to 0 then v8 would choose an appropriate size of the thread pool based on the number of online processors.
Based on the conversation in #4243 this implements a way to increase and decrease the size of the thread pool used in v8. Currently v8 restricts the thread pool size to `kMaxThreadPoolSize` which at this commit is (4). So it is only possible to decrease the thread pool size at the time of this commit. However with changes upstream this could change at a later date. If set to 0 then v8 would choose an appropriate size of the thread pool based on the number of online processors. PR-URL: #4344 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Based on the conversation in #4243 this implements a way to increase and decrease the size of the thread pool used in v8. Currently v8 restricts the thread pool size to `kMaxThreadPoolSize` which at this commit is (4). So it is only possible to decrease the thread pool size at the time of this commit. However with changes upstream this could change at a later date. If set to 0 then v8 would choose an appropriate size of the thread pool based on the number of online processors. PR-URL: #4344 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
Based on the conversation in #4243 this implements a way to increase and decrease the size of the thread pool used in v8. Currently v8 restricts the thread pool size to `kMaxThreadPoolSize` which at this commit is (4). So it is only possible to decrease the thread pool size at the time of this commit. However with changes upstream this could change at a later date. If set to 0 then v8 would choose an appropriate size of the thread pool based on the number of online processors. PR-URL: #4344 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
7da4fd4
to
c7066fb
Compare
Is this PR still being worked on? ping @tangxinfa |
It's been subsumed by PR #4344. I'll close this one. |
By passing
const int thread_pool_size = 0
toCreateDefaultPlatform
we allow v8 to choose sensible defaults based on the currently online
processors.
Benchmarking on my local machine saw no performance regressions; however it is dual core and hyper-threaded and would of used the same thread count as previously - I assume that this will benefit machines with more online processors; however I am curious if this would affect machines with only one core.