From: Jérôme Benoit Date: Thu, 21 Jan 2021 17:22:38 +0000 (+0100) Subject: Don't access singleton instance attribute directly X-Git-Tag: v1.0.1-0~130 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4fa59b8a2888956b1a74b976b47ce732970d641e;p=e-mobility-charging-stations-simulator.git Don't access singleton instance attribute directly And sone cleanups. Signed-off-by: Jérôme Benoit --- diff --git a/src/assets/config-template.json b/src/assets/config-template.json index e6ea2f33..0104ade3 100644 --- a/src/assets/config-template.json +++ b/src/assets/config-template.json @@ -5,7 +5,7 @@ "distributeStationsToTenantsEqually": true, "statisticsDisplayInterval": 60, "useWorkerPool": false, - "workerMaxPoolSize": 16, + "workerPoolMaxSize": 16, "chargingStationsPerWorker": 1, "stationTemplateURLs": [ { diff --git a/src/charging-station/Worker.ts b/src/charging-station/Worker.ts index 66e21329..a4cd80a9 100644 --- a/src/charging-station/Worker.ts +++ b/src/charging-station/Worker.ts @@ -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; } } diff --git a/src/start.ts b/src/start.ts index 1e0916c2..94af1c54 100644 --- a/src/start.ts +++ b/src/start.ts @@ -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 diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index 604e249b..2c15a6f5 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -11,7 +11,7 @@ export default interface ConfigurationData { autoReconnectMaxRetries?: number; distributeStationsToTenantsEqually?: boolean; useWorkerPool?: boolean; - workerMaxPoolSize?: number; + workerPoolMaxSize?: number; chargingStationsPerWorker?: number; logFormat?: string; logLevel?: string; diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index eb1992b3..f0054ede 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -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 {