Skip to content

Commit 6f65ab3

Browse files
committed
Refactor UV_THREADPOOL_SIZE
1 parent b539420 commit 6f65ab3

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
Error.stackTraceLimit = Infinity;
66

77
require('events').EventEmitter.defaultMaxListeners = 128;
8-
process.env.UV_THREADPOOL_SIZE = process.env.UV_THREADPOOL_SIZE || `${Math.min(Math.max(4, require('os').cpus().length), 1024)}`;
8+
9+
if (process.env.UV_THREADPOOL_SIZE == null) {
10+
let uvThreadpoolSize = 4;
11+
const cpus = require('os').cpus().length; // some environments returns 0
12+
if (cpus > uvThreadpoolSize) uvThreadpoolSize = cpus;
13+
if (uvThreadpoolSize > 1024) uvThreadpoolSize = 1024;
14+
process.env.UV_THREADPOOL_SIZE = uvThreadpoolSize.toString();
15+
}
916

1017
import * as os from 'os';
1118
import * as cluster from 'cluster';

0 commit comments

Comments
 (0)