From: Jérôme Benoit Date: Wed, 12 Jul 2023 14:29:03 +0000 (+0200) Subject: fix: fix elementsPerWorker automatic calculation X-Git-Tag: v1.2.18~45 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=34c200d5d7239aed80b68da98b664b573bf6e8bd;p=e-mobility-charging-stations-simulator.git fix: fix elementsPerWorker automatic calculation Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 96e7b8ce..1550f6a7 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -212,12 +212,12 @@ export class Bootstrap extends EventEmitter { } private initializeWorkerImplementation(): void { - let elementsPerWorker = WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER; - if ( - Configuration.getWorker()?.elementsPerWorker === 'auto' && - this.numberOfChargingStations > availableParallelism() - ) { - elementsPerWorker = Math.round(this.numberOfChargingStations / availableParallelism()); + let elementsPerWorker: number; + if (Configuration.getWorker()?.elementsPerWorker === 'auto') { + elementsPerWorker = + this.numberOfChargingStations > availableParallelism() + ? Math.round(this.numberOfChargingStations / availableParallelism()) + : 1; } this.workerImplementation === null && (this.workerImplementation = WorkerFactory.getWorkerImplementation( @@ -228,7 +228,8 @@ export class Bootstrap extends EventEmitter { elementStartDelay: Configuration.getWorker().elementStartDelay, poolMaxSize: Configuration.getWorker().poolMaxSize, poolMinSize: Configuration.getWorker().poolMinSize, - elementsPerWorker, + elementsPerWorker: + elementsPerWorker ?? (Configuration.getWorker().elementsPerWorker as number), poolOptions: { workerChoiceStrategy: Configuration.getWorker().poolStrategy, messageHandler: this.messageHandler.bind(this) as (message: unknown) => void,