Skip to content

Commit

Permalink
Only use os.cpus() and filter out core like physical-cpu-count did (#142
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
reel authored and devongovett committed Dec 11, 2017
1 parent 7bfe232 commit 9d319af
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/WorkerFarm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const {EventEmitter} = require('events');
const os = require('os');
const Farm = require('worker-farm/lib/farm');
const promisify = require('./utils/promisify');

Expand All @@ -8,7 +9,7 @@ class WorkerFarm extends Farm {
constructor(options) {
let opts = {
autoStart: true,
maxConcurrentWorkers: require('physical-cpu-count')
maxConcurrentWorkers: getNumWorkers(),
};

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

function getNumWorkers() {
let cores;
try {
cores = require('physical-cpu-count');
} catch (err) {
cores = os.cpus().length;
}
return cores || 1;
}

module.exports = WorkerFarm;

0 comments on commit 9d319af

Please sign in to comment.