From 4990e94a20f058bc59049c30c71a5e2b3b090397 Mon Sep 17 00:00:00 2001 From: Brandon DuRette Date: Thu, 23 Jul 2026 13:54:08 -0500 Subject: [PATCH 1/3] Use availableParallelism for determining maxWorkers Fixes #568 --- src/environment.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/environment.js b/src/environment.js index e20797a5..5a69106c 100644 --- a/src/environment.js +++ b/src/environment.js @@ -24,7 +24,8 @@ module.exports.isMainThread = module.exports.platform === 'node' : typeof Window !== 'undefined'; // determines the number of cpus available +var os = require('os') module.exports.cpus = module.exports.platform === 'browser' ? self.navigator.hardwareConcurrency - : require('os').cpus().length; + : (((typeof os?.availableParallelism === "function") && os.availableParallelism()) || os.cpus().length); From 268f9f4c7188bd3e3bfc93ee9ecf4ff80147a566 Mon Sep 17 00:00:00 2001 From: Brandon DuRette Date: Thu, 23 Jul 2026 14:07:19 -0500 Subject: [PATCH 2/3] Update tests to reflect change to using parallelism --- test/Pool.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/Pool.test.js b/test/Pool.test.js index 9bf290c5..7c293685 100644 --- a/test/Pool.test.js +++ b/test/Pool.test.js @@ -885,11 +885,11 @@ describe('Pool', function () { }); }); - it('should take number of cpus minus one as default maxWorkers', function () { + it('should take the available parallelism minus one as default maxWorkers', function () { var pool = createPool(); - var cpus = require('os').cpus(); - assert.strictEqual(pool.maxWorkers, cpus.length - 1); + var parallelism = require('os').availableParallelism(); + assert.strictEqual(pool.maxWorkers, parallelism - 1); return pool.terminate(); }); @@ -908,19 +908,19 @@ describe('Pool', function () { }, TypeError); }); - it('should create number of cpus minus one when minWorkers set to \'max\'', function () { + it('should create available parallelism minus one when minWorkers set to \'max\'', function () { var pool = createPool({minWorkers:'max'}); - var cpus = require('os').cpus(); - assert.strictEqual(pool.workers.length, cpus.length - 1); + var parallelism = require('os').availableParallelism(); + assert.strictEqual(pool.workers.length, parallelism - 1); return pool.terminate(); }); it('should increase maxWorkers to match minWorkers', function () { - var cpus = require('os').cpus(); - var count = cpus.length + 2; - var tasksCount = cpus.length * 2; + var parallelism = require('os').availableParallelism(); + var count = parallelism + 2; + var tasksCount = parallelism * 2; var pool = createPool({minWorkers: count}); var tasks = [] From ca7a864f3f42643755bc7cd176d73d07e25ffb0f Mon Sep 17 00:00:00 2001 From: Brandon DuRette Date: Thu, 23 Jul 2026 14:13:26 -0500 Subject: [PATCH 3/3] Remove fallback to cpus. --- src/environment.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/environment.js b/src/environment.js index 5a69106c..5bfac301 100644 --- a/src/environment.js +++ b/src/environment.js @@ -24,8 +24,7 @@ module.exports.isMainThread = module.exports.platform === 'node' : typeof Window !== 'undefined'; // determines the number of cpus available -var os = require('os') module.exports.cpus = module.exports.platform === 'browser' ? self.navigator.hardwareConcurrency - : (((typeof os?.availableParallelism === "function") && os.availableParallelism()) || os.cpus().length); + : require('os').availableParallelism();