From 34c200d5d7239aed80b68da98b664b573bf6e8bd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 12 Jul 2023 16:29:03 +0200 Subject: [PATCH] fix: fix elementsPerWorker automatic calculation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) 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, -- 2.34.1