Constify some hardcoded worker related numbers
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 19 May 2021 22:16:37 +0000 (00:16 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 19 May 2021 22:16:37 +0000 (00:16 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/utils/Configuration.ts
src/utils/Constants.ts
src/worker/WorkerFactory.ts

index 0926115ce41a0f016b75c799114d8a4553806695..a347969683fe546333c3db870934c64b55a4f369 100644 (file)
@@ -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 {
index 8b1df1ca31983bbd400ec0a0c039be124de111d4..706ef41cc3291189c7e2ffa148a14523167c832c 100644 (file)
@@ -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;
 }
index f4307be6bde3b159d5e35ccbf6159061046456bf..3784e7ab0c572f36a30de55d1181309fa4e2191e 100644 (file)
@@ -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<T>(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<T>(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<T>(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay, options.poolOptions);
       default:
         return null;