| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6f0bc09 commit 56f22ea
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1569,11 +1569,12 @@ added: v5.10.0 | |||
| 1569 | 1569 | ||
| 1570 | 1570 | Set V8's thread pool size which will be used to allocate background jobs. | |
| 1571 | 1571 | ||
| 1572 | - If set to `0` then V8 will choose an appropriate size of the thread pool based | ||
| 1573 | - on the number of online processors. | ||
| 1572 | + If set to `0` then Node.js will choose an appropriate size of the thread pool | ||
| 1573 | + based on an estimate of the amount of parallelism. | ||
| 1574 | 1574 | ||
| 1575 | - If the value provided is larger than V8's maximum, then the largest value | ||
| 1576 | - will be chosen. | ||
| 1575 | + The amount of parallelism refers to the number of computations that can be | ||
| 1576 | + carried out simultaneously in a given machine. In general, it's the same as the | ||
| 1577 | + amount of CPUs, but it may diverge in environments such as VMs or containers. | ||
| 1577 | 1578 | ||
| 1578 | 1579 | ### `--watch` | |
| 1579 | 1580 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,13 @@ static void PlatformWorkerThread(void* data) { | |||
| 45 | 45 | } | |
| 46 | 46 | } | |
| 47 | 47 | ||
| 48 | + static int GetActualThreadPoolSize(int thread_pool_size) { | ||
| 49 | + if (thread_pool_size < 1) { | ||
| 50 | + thread_pool_size = uv_available_parallelism() - 1; | ||
| 51 | + } | ||
| 52 | + return std::max(thread_pool_size, 1); | ||
| 53 | + } | ||
| 54 | + | ||
| 48 | 55 | } // namespace | |
| 49 | 56 | ||
| 50 | 57 | class WorkerThreadsTaskRunner::DelayedTaskScheduler { | |
@@ -340,6 +347,8 @@ NodePlatform::NodePlatform(int thread_pool_size, | |||
| 340 | 347 | // current v8::Platform instance. | |
| 341 | 348 | SetTracingController(tracing_controller_); | |
| 342 | 349 | DCHECK_EQ(GetTracingController(), tracing_controller_); | |
| 350 | + | ||
| 351 | + thread_pool_size = GetActualThreadPoolSize(thread_pool_size); | ||
| 343 | 352 | worker_thread_task_runner_ = | |
| 344 | 353 | std::make_shared<WorkerThreadsTaskRunner>(thread_pool_size); | |
| 345 | 354 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,10 @@ | |||
| 1 | + // Flags: --v8-pool-size=0 --expose-gc | ||
| 2 | + | ||
| 3 | + 'use strict'; | ||
| 4 | + | ||
| 5 | + require('../common'); | ||
| 6 | + | ||
| 7 | + // This verifies that V8 tasks scheduled by GC are handled on worker threads if | ||
| 8 | + // `--v8-pool-size=0` is given. The worker threads are managed by Node.js' | ||
| 9 | + // `v8::Platform` implementation. | ||
| 10 | + globalThis.gc(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments