From 1f0052b9fa7d0a13a1e85d8a0f761ba250af7fd5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 20 May 2021 00:16:37 +0200 Subject: [PATCH] Constify some hardcoded worker related numbers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/utils/Configuration.ts | 6 +++--- src/utils/Constants.ts | 3 +++ src/worker/WorkerFactory.ts | 8 ++++---- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 0926115c..a3479696 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -58,12 +58,12 @@ export default class Configuration { } static getWorkerPoolMinSize(): number { - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMinSize') ? Configuration.getConfig().workerPoolMinSize : 4; + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMinSize') ? Configuration.getConfig().workerPoolMinSize : Constants.DEFAULT_WORKER_POOL_MIN_SIZE; } static getWorkerPoolMaxSize(): number { Configuration.deprecateConfigurationKey('workerPoolSize;', 'Use \'workerPoolMaxSize\' instead'); - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMaxSize') ? Configuration.getConfig().workerPoolMaxSize : 16; + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMaxSize') ? Configuration.getConfig().workerPoolMaxSize : Constants.DEFAULT_WORKER_POOL_MAX_SIZE; } static getWorkerPoolStrategy(): WorkerChoiceStrategy { @@ -71,7 +71,7 @@ export default class Configuration { } static getChargingStationsPerWorker(): number { - return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'chargingStationsPerWorker') ? Configuration.getConfig().chargingStationsPerWorker : 1; + return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'chargingStationsPerWorker') ? Configuration.getConfig().chargingStationsPerWorker : Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER; } static getLogConsole(): boolean { diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 8b1df1ca..706ef41c 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -33,4 +33,7 @@ export default class Constants { static readonly WORKER_START_DELAY = 500; static readonly WORKER_POOL_MAX_INACTIVE_TIME = 60000; + static readonly DEFAULT_WORKER_POOL_MIN_SIZE = 4; + static readonly DEFAULT_WORKER_POOL_MAX_SIZE = 16; + static readonly DEFAULT_CHARGING_STATIONS_PER_WORKER = 1; } diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index f4307be6..3784e7ab 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -16,14 +16,14 @@ export default class WorkerFactory { options.startDelay = options.startDelay ?? Constants.WORKER_START_DELAY; switch (workerProcessType) { case WorkerProcessType.WORKER_SET: - options.elementsPerWorker = options.elementsPerWorker ?? 1; + options.elementsPerWorker = options.elementsPerWorker ?? Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER; return new WorkerSet(workerScript, options.elementsPerWorker, options.startDelay); case WorkerProcessType.STATIC_POOL: - options.poolMaxSize = options.poolMaxSize ?? 16; + options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE; return new WorkerStaticPool(workerScript, options.poolMaxSize, options.startDelay, options.poolOptions); case WorkerProcessType.DYNAMIC_POOL: - options.poolMinSize = options.poolMinSize ?? 4; - options.poolMaxSize = options.poolMaxSize ?? 16; + options.poolMinSize = options.poolMinSize ?? Constants.DEFAULT_WORKER_POOL_MIN_SIZE; + options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE; return new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay, options.poolOptions); default: return null; -- 2.34.1