GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: set an appropriate thread pool size if given `--v8-pool-size=0` · nodejs/node@56f22ea

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • cli.md
  • src
    • node_platform.cc
  • test/parallel
    • test-v8-flag-pool-size-0.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+5-4Lines changed: 5 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1569,11 +1569,12 @@ added: v5.10.0
15691569

15701570
Set V8's thread pool size which will be used to allocate background jobs.
15711571

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.
15741574

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.
15771578

15781579
### `--watch`
15791580

Collapse file

‎src/node_platform.cc‎

Copy file name to clipboardExpand all lines: src/node_platform.cc
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ static void PlatformWorkerThread(void* data) {
4545
}
4646
}
4747

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+
4855
} // namespace
4956

5057
class WorkerThreadsTaskRunner::DelayedTaskScheduler {
@@ -340,6 +347,8 @@ NodePlatform::NodePlatform(int thread_pool_size,
340347
// current v8::Platform instance.
341348
SetTracingController(tracing_controller_);
342349
DCHECK_EQ(GetTracingController(), tracing_controller_);
350+
351+
thread_pool_size = GetActualThreadPoolSize(thread_pool_size);
343352
worker_thread_task_runner_ =
344353
std::make_shared<WorkerThreadsTaskRunner>(thread_pool_size);
345354
}
Collapse file

‎test/parallel/test-v8-flag-pool-size-0.js‎

Copy file name to clipboard
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.