mirror of https://github.com/status-im/metro.git
limit number of workers
Summary:This limits the number of spawned transformation workers depending on the number of available cores (`n`): ``` n < 3 → n n < 8 → floor(3/4 * n) n < 24 → floor(3/8 * n + 3) // factor going from 3/4 to 1/2 n >= 24 → floor(n / 2) ``` Reviewed By: bestander Differential Revision: D2999894 fb-gh-sync-id: 0163240b5f066432f9ba07161c0dfa2ec767ba58 shipit-source-id: 0163240b5f066432f9ba07161c0dfa2ec767ba58
This commit is contained in:
parent
a8a501b5cf
commit
d13b75794f
|
@ -12,6 +12,7 @@ const ModuleTransport = require('../lib/ModuleTransport');
|
||||||
const Promise = require('promise');
|
const Promise = require('promise');
|
||||||
const declareOpts = require('../lib/declareOpts');
|
const declareOpts = require('../lib/declareOpts');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
const temp = require('temp');
|
const temp = require('temp');
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
const workerFarm = require('worker-farm');
|
const workerFarm = require('worker-farm');
|
||||||
|
@ -60,6 +61,23 @@ const validateOpts = declareOpts({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const maxConcurrentWorkers = ((cores, override) => {
|
||||||
|
if (override) {
|
||||||
|
return Math.min(cores, override);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cores < 3) {
|
||||||
|
return cores;
|
||||||
|
}
|
||||||
|
if (cores < 8) {
|
||||||
|
return Math.floor(cores * 0.75);
|
||||||
|
}
|
||||||
|
if (cores < 24) {
|
||||||
|
return Math.floor(3/8 * cores + 3); // between cores *.75 and cores / 2
|
||||||
|
}
|
||||||
|
return cores / 2;
|
||||||
|
})(os.cpus().length, process.env.REACT_NATIVE_MAX_WORKERS);
|
||||||
|
|
||||||
class Transformer {
|
class Transformer {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
const opts = this._opts = validateOpts(options);
|
const opts = this._opts = validateOpts(options);
|
||||||
|
@ -87,6 +105,7 @@ class Transformer {
|
||||||
this._workers = workerFarm({
|
this._workers = workerFarm({
|
||||||
autoStart: true,
|
autoStart: true,
|
||||||
maxConcurrentCallsPerWorker: 1,
|
maxConcurrentCallsPerWorker: 1,
|
||||||
|
maxConcurrentWorkers: maxConcurrentWorkers,
|
||||||
maxCallsPerWorker: MAX_CALLS_PER_WORKER,
|
maxCallsPerWorker: MAX_CALLS_PER_WORKER,
|
||||||
maxCallTime: opts.transformTimeoutInterval,
|
maxCallTime: opts.transformTimeoutInterval,
|
||||||
maxRetries: MAX_RETRIES,
|
maxRetries: MAX_RETRIES,
|
||||||
|
|
Loading…
Reference in New Issue