interpret maxWorkers config in lib/env instead of in worker handler

This commit is contained in:
ansuz 2022-12-07 13:04:07 +05:30
parent bd82e86228
commit c762353cad
2 changed files with 10 additions and 17 deletions

View File

@ -205,7 +205,7 @@ module.exports.create = function (config) {
// but it is referenced in Quota
domain: config.domain,
maxWorkers: config.maxWorkers,
maxWorkers: undefined,
disableIntegratedTasks: config.disableIntegratedTasks || false,
disableIntegratedEviction: typeof(config.disableIntegratedEviction) === 'undefined'? true: config.disableIntegratedEviction,
lastEviction: +new Date(),
@ -213,6 +213,14 @@ module.exports.create = function (config) {
commandTimers: {},
};
(function () {
var max = config.maxWorkers;
// if the supplied value is not a positive number, leave maxWorkers undefined
// one worker will be created for each CPU core
if (typeof(max) !== 'number' || isNaN(max) || max < 1) { return; }
Env.maxWorkers = max;
}());
(function () {
// mode can be FRESH (default), DEV, or PACKAGE
if (process.env.PACKAGE) {

View File

@ -260,22 +260,7 @@ Workers.initialize = function (Env, config, _cb) {
};
nThen(function (w) {
const max = config.maxWorkers;
var limit;
if (typeof(max) !== 'undefined') {
// the admin provided a limit on the number of workers
if (typeof(max) === 'number' && !isNaN(max)) {
if (max < 1) {
Log.info("INSUFFICIENT_MAX_WORKERS", max);
limit = 1;
}
limit = max;
} else {
Log.error("INVALID_MAX_WORKERS", '[' + max + ']');
}
}
var limit = Env.maxWorkers;
var logged;
OS.cpus().forEach(function (cpu, index) {