@@ -4051,6 +4051,15 @@ Wed May 12 2021 20:30:48 GMT+0100 (Irish Standard Time)
40514051
40524052### ` UV_THREADPOOL_SIZE=size `
40534053
4054+ <!-- YAML
4055+ changes:
4056+ - version: REPLACEME
4057+ pr-url: https://github.com/nodejs/node/pull/XXXX
4058+ description: Node.js now automatically sets `UV_THREADPOOL_SIZE` to the
4059+ available CPU parallelism (with a minimum of 4 and a maximum
4060+ of 1024) when the environment variable is not already set.
4061+ -->
4062+
40544063Set the number of threads used in libuv's threadpool to ` size ` threads.
40554064
40564065Asynchronous system APIs are used by Node.js whenever possible, but where they
@@ -4064,15 +4073,22 @@ on synchronous system APIs. Node.js APIs that use the threadpool are:
40644073* ` dns.lookup() `
40654074* all ` zlib ` APIs, other than those that are explicitly synchronous
40664075
4076+ If this environment variable is not set, Node.js automatically sizes the
4077+ threadpool based on the available CPU parallelism, using a minimum of ` 4 `
4078+ threads and a maximum of ` 1024 ` . This ensures better default performance on
4079+ machines with many CPU cores, where the previous fixed default of ` 4 ` threads
4080+ could become a bottleneck.
4081+
40674082Because libuv's threadpool has a fixed size, it means that if for whatever
40684083reason any of these APIs takes a long time, other (seemingly unrelated) APIs
40694084that run in libuv's threadpool will experience degraded performance. In order to
40704085mitigate this issue, one potential solution is to increase the size of libuv's
40714086threadpool by setting the ` 'UV_THREADPOOL_SIZE' ` environment variable to a value
4072- greater than ` 4 ` (its current default value). However, setting this from inside
4073- the process using ` process.env.UV_THREADPOOL_SIZE=size ` is not guranteed to work
4074- as the threadpool would have been created as part of the runtime initialisation
4075- much before user code is run. For more information, see the [ libuv threadpool documentation] [ ] .
4087+ greater than the automatically computed default. However, setting this from
4088+ inside the process using ` process.env.UV_THREADPOOL_SIZE=size ` is not guaranteed
4089+ to work as the threadpool would have been created as part of the runtime
4090+ initialisation much before user code is run. For more information, see the
4091+ [ libuv threadpool documentation] [ ] .
40764092
40774093## Useful V8 options
40784094
0 commit comments