Skip to content

Commit 0d0c57f

Browse files
tomgcoevanlucas
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 <jasnell@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent aebe624 commit 0d0c57f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

doc/node.1

Lines changed: 7 additions & 1 deletion
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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ static const char** preload_modules = nullptr;
145145
static bool use_debug_agent = false;
146146
static bool debug_wait_connect = false;
147147
static int debug_port = 5858;
148+
static const int v8_default_thread_pool_size = 4;
149+
static int v8_thread_pool_size = v8_default_thread_pool_size;
148150
static bool prof_process = false;
149151
static bool v8_is_profiling = false;
150152
static bool node_is_initialized = false;
@@ -169,7 +171,6 @@ static uv_async_t dispatch_debug_messages_async;
169171
static node::atomic<Isolate*> node_isolate;
170172
static v8::Platform* default_platform;
171173

172-
173174
static void PrintErrorString(const char* format, ...) {
174175
va_list ap;
175176
va_start(ap, format);
@@ -3316,6 +3317,7 @@ static void PrintHelp() {
33163317
" --zero-fill-buffers automatically zero-fill all newly allocated\n"
33173318
" Buffer and SlowBuffer instances\n"
33183319
" --v8-options print v8 command line options\n"
3320+
" --v8-pool-size=num set v8's thread pool size\n"
33193321
#if HAVE_OPENSSL
33203322
" --tls-cipher-list=val use an alternative default TLS cipher list\n"
33213323
#endif
@@ -3459,6 +3461,8 @@ static void ParseArgs(int* argc,
34593461
} else if (strcmp(arg, "--v8-options") == 0) {
34603462
new_v8_argv[new_v8_argc] = "--help";
34613463
new_v8_argc += 1;
3464+
} else if (strncmp(arg, "--v8-pool-size=", 15) == 0) {
3465+
v8_thread_pool_size = atoi(arg + 15);
34623466
#if HAVE_OPENSSL
34633467
} else if (strncmp(arg, "--tls-cipher-list=", 18) == 0) {
34643468
default_cipher_list = arg + 18;
@@ -4266,8 +4270,7 @@ int Start(int argc, char** argv) {
42664270
V8::SetEntropySource(crypto::EntropySource);
42674271
#endif
42684272

4269-
const int thread_pool_size = 4;
4270-
default_platform = v8::platform::CreateDefaultPlatform(thread_pool_size);
4273+
default_platform = v8::platform::CreateDefaultPlatform(v8_thread_pool_size);
42714274
V8::InitializePlatform(default_platform);
42724275
V8::Initialize();
42734276

0 commit comments

Comments
 (0)