Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ module.exports.isMainThread = module.exports.platform === 'node'
// determines the number of cpus available
module.exports.cpus = module.exports.platform === 'browser'
? self.navigator.hardwareConcurrency
: require('os').cpus().length;
: require('os').availableParallelism();

18 changes: 9 additions & 9 deletions test/Pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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 = []
Expand Down