Don't access singleton instance attribute directly
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 21 Jan 2021 17:22:38 +0000 (18:22 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 21 Jan 2021 17:22:38 +0000 (18:22 +0100)
And sone cleanups.

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/assets/config-template.json
src/charging-station/Worker.ts
src/start.ts
src/types/ConfigurationData.ts
src/utils/Configuration.ts

index e6ea2f33896cb58023d30f58b7d563d33650f34a..0104ade3a869fa4dbef4316f98bd4c2fd76f3a6f 100644 (file)
@@ -5,7 +5,7 @@
   "distributeStationsToTenantsEqually": true,
   "statisticsDisplayInterval": 60,
   "useWorkerPool": false,
-  "workerMaxPoolSize": 16,
+  "workerPoolMaxSize": 16,
   "chargingStationsPerWorker": 1,
   "stationTemplateURLs": [
     {
index 66e21329f804f703542b98ba04101d1604935777..a4cd80a9a4ed6796408e60b1dfc0743a8dbdbea0 100644 (file)
@@ -20,7 +20,7 @@ export default class Wrk {
     this._workerData = workerData;
     this._workerScript = workerScript;
     if (Configuration.useWorkerPool()) {
-      WorkerPool.maxConcurrentWorkers = Configuration.getWorkerMaxPoolSize();
+      WorkerPool.maxConcurrentWorkers = Configuration.getWorkerPoolMaxSize();
     }
   }
 
@@ -49,7 +49,18 @@ export default class Wrk {
       return;
     }
     this._workerData = workerData;
-    this._worker.postMessage({ id : Constants.START_WORKER_ELEMENT, workerData: workerData });
+    this._worker.postMessage({ id: Constants.START_WORKER_ELEMENT, workerData: workerData });
+  }
+
+  /**
+   *
+   * @return {number}
+   * @public
+   */
+  public getWorkerPoolSize(): number {
+    if (Configuration.useWorkerPool()) {
+      return WorkerPool.getPoolSize();
+    }
   }
 
   /**
@@ -88,15 +99,6 @@ export default class Wrk {
       this._worker = worker;
     });
   }
-
-  /**
-   *
-   * @return {number}
-   * @public
-   */
-  public getPoolSize(): number {
-    return WorkerPool.getPoolSize();
-  }
 }
 
 
@@ -118,6 +120,6 @@ class WorkerPool {
   }
 
   public static getPoolSize(): number {
-    return WorkerPool._instance.size;
+    return WorkerPool.getInstance().size;
   }
 }
index 1e0916c23bdbc80b7e46c9f5cc86c126f84d5e57..94af1c54fb8999ef42e6c5f3e5b1b5e020bd772f 100644 (file)
@@ -25,8 +25,9 @@ class Bootstrap {
               if (Configuration.useWorkerPool()) {
                 worker = new Wrk('./dist/charging-station/StationWorker.js', workerData);
                 worker.start().catch(() => { });
-                numConcurrentWorkers = worker.getPoolSize();
+                numConcurrentWorkers = worker.getWorkerPoolSize();
                 numStationsTotal = numConcurrentWorkers;
+                // Start Wrk sequentially to optimize memory at start time
                 await Utils.sleep(Constants.START_WORKER_DELAY);
               } else if (!Configuration.useWorkerPool() && (chargingStationsPerWorkerCounter === 0 || chargingStationsPerWorkerCounter === chargingStationsPerWorker)) {
                 // Start new Wrk with one charging station
@@ -54,12 +55,10 @@ class Bootstrap {
       }
       if (numStationsTotal === 0) {
         console.log('No charging station template enabled in configuration, exiting');
+      } else if (Configuration.useWorkerPool()) {
+        console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s) and ' + numConcurrentWorkers.toString() + '/' + Configuration.getWorkerPoolMaxSize().toString() + ' worker(s) concurrently running');
       } else {
-        if (Configuration.useWorkerPool()) {
-          console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s) and ' + numConcurrentWorkers.toString() + '/' + Configuration.getWorkerMaxPoolSize() + ' worker(s) concurrently running');
-        } else {
-          console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s) and ' + numConcurrentWorkers.toString() + ' worker(s) concurrently running');
-        }
+        console.log('Charging station simulator started with ' + numStationsTotal.toString() + ' charging station(s) and ' + numConcurrentWorkers.toString() + ' worker(s) concurrently running');
       }
     } catch (error) {
       // eslint-disable-next-line no-console
index 604e249bd37b4ad1b6dbbaabe1dff3e901b44f41..2c15a6f50479a545d92fa2a3ab9ee8fd3a6e8c62 100644 (file)
@@ -11,7 +11,7 @@ export default interface ConfigurationData {
   autoReconnectMaxRetries?: number;
   distributeStationsToTenantsEqually?: boolean;
   useWorkerPool?: boolean;
-  workerMaxPoolSize?: number;
+  workerPoolMaxSize?: number;
   chargingStationsPerWorker?: number;
   logFormat?: string;
   logLevel?: string;
index eb1992b3dc33a75a4a063897dfcb48da93ec1132..f0054edef9f13b67c9404b0ee1685a1fc9a73749 100644 (file)
@@ -41,8 +41,9 @@ export default class Configuration {
     return Configuration.getConfig().useWorkerPool;
   }
 
-  static getWorkerMaxPoolSize(): number {
-    return Configuration.getConfig().workerMaxPoolSize;
+  static getWorkerPoolMaxSize(): number {
+    Configuration.deprecateConfigurationKey('workerPoolSize;', 'Use \'workerPoolMaxSize\' instead');
+    return Configuration.getConfig().workerPoolMaxSize;
   }
 
   static getChargingStationsPerWorker(): number {