Skip to content

Commit 9d319af

Browse files
reeldevongovett
authored andcommitted
Only use os.cpus() and filter out core like physical-cpu-count did (#142)
* Only use os.cpus() and filter out core like physical-cpu-count did The problem is with heroku and some CI, the physical-cpu-count linux branch requires a binary and access not provided by these environments. * using physical-cpu-count and defaulting to os.cpus() * get the actual length, should be good
1 parent 7bfe232 commit 9d319af

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/WorkerFarm.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const {EventEmitter} = require('events');
2+
const os = require('os');
23
const Farm = require('worker-farm/lib/farm');
34
const promisify = require('./utils/promisify');
45

@@ -8,7 +9,7 @@ class WorkerFarm extends Farm {
89
constructor(options) {
910
let opts = {
1011
autoStart: true,
11-
maxConcurrentWorkers: require('physical-cpu-count')
12+
maxConcurrentWorkers: getNumWorkers(),
1213
};
1314

1415
super(opts, require.resolve('./worker'));
@@ -86,4 +87,14 @@ for (let key in EventEmitter.prototype) {
8687
WorkerFarm.prototype[key] = EventEmitter.prototype[key];
8788
}
8889

90+
function getNumWorkers() {
91+
let cores;
92+
try {
93+
cores = require('physical-cpu-count');
94+
} catch (err) {
95+
cores = os.cpus().length;
96+
}
97+
return cores || 1;
98+
}
99+
89100
module.exports = WorkerFarm;

0 commit comments

Comments
 (0)