Skip to content

Commit 03e07d3

Browse files
tomgcojasnell
authored andcommitted
src: override v8 thread defaults using cli options
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]>
1 parent 8baaa25 commit 03e07d3

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

doc/node.1

+7-1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ Process v8 profiler output generated using the v8 option \fB\-\-prof\fR
9999
.BR \-\-v8\-options
100100
Print v8 command line options.
101101

102+
.TP
103+
.BR \-\-v8\-pool\-size =\fInum\fR
104+
Set v8's thread pool size which will be used to allocate background jobs.
105+
If set to 0 then v8 will choose an appropriate size of the thread pool based
106+
on the number of online processors. If the value provided is larger than v8's
107+
max then the largest value will be chosen.
108+
102109
.TP
103110
.BR \-\-tls\-cipher\-list =\fIlist\fR
104111
Specify an alternative default TLS cipher list. (Requires Node.js to be built with crypto support. (Default))
@@ -115,7 +122,6 @@ Force FIPS-compliant crypto on startup. (Cannot be disabled from script code.) (
115122
.BR \-\-icu\-data\-dir =\fIfile\fR
116123
Specify ICU data load path. (overrides \fBNODE_ICU_DATA\fR)
117124

118-
119125
.SH ENVIRONMENT VARIABLES
120126

121127
.TP

src/node.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ static const char** preload_modules = nullptr;
148148
static bool use_debug_agent = false;
149149
static bool debug_wait_connect = false;
150150
static int debug_port = 5858;
151+
static const int v8_default_thread_pool_size = 4;
152+
static int v8_thread_pool_size = v8_default_thread_pool_size;
151153
static bool prof_process = false;
152154
static bool v8_is_profiling = false;
153155
static bool node_is_initialized = false;
@@ -178,7 +180,6 @@ static uv_async_t dispatch_debug_messages_async;
178180
static node::atomic<Isolate*> node_isolate;
179181
static v8::Platform* default_platform;
180182

181-
182183
static void PrintErrorString(const char* format, ...) {
183184
va_list ap;
184185
va_start(ap, format);
@@ -3319,6 +3320,7 @@ static void PrintHelp() {
33193320
" --zero-fill-buffers automatically zero-fill all newly allocated\n"
33203321
" Buffer and SlowBuffer instances\n"
33213322
" --v8-options print v8 command line options\n"
3323+
" --v8-pool-size=num set v8's thread pool size\n"
33223324
#if HAVE_OPENSSL
33233325
" --tls-cipher-list=val use an alternative default TLS cipher list\n"
33243326
#if NODE_FIPS_MODE
@@ -3466,6 +3468,8 @@ static void ParseArgs(int* argc,
34663468
} else if (strcmp(arg, "--v8-options") == 0) {
34673469
new_v8_argv[new_v8_argc] = "--help";
34683470
new_v8_argc += 1;
3471+
} else if (strncmp(arg, "--v8-pool-size=", 15) == 0) {
3472+
v8_thread_pool_size = atoi(arg + 15);
34693473
#if HAVE_OPENSSL
34703474
} else if (strncmp(arg, "--tls-cipher-list=", 18) == 0) {
34713475
default_cipher_list = arg + 18;
@@ -4285,8 +4289,7 @@ int Start(int argc, char** argv) {
42854289
V8::SetEntropySource(crypto::EntropySource);
42864290
#endif
42874291

4288-
const int thread_pool_size = 4;
4289-
default_platform = v8::platform::CreateDefaultPlatform(thread_pool_size);
4292+
default_platform = v8::platform::CreateDefaultPlatform(v8_thread_pool_size);
42904293
V8::InitializePlatform(default_platform);
42914294
V8::Initialize();
42924295

0 commit comments

Comments
 (0)