- this.workerImplementation === null &&
- (this.workerImplementation = WorkerFactory.getWorkerImplementation<ChargingStationWorkerData>(
- this.workerScript,
- workerConfiguration.processType!,
- {
- workerStartDelay: workerConfiguration.startDelay,
- elementStartDelay: workerConfiguration.elementStartDelay,
- poolMaxSize: workerConfiguration.poolMaxSize!,
- poolMinSize: workerConfiguration.poolMinSize!,
- elementsPerWorker: elementsPerWorker ?? (workerConfiguration.elementsPerWorker as number),
- poolOptions: {
- messageHandler: this.messageHandler.bind(this) as (message: unknown) => void,
- },
- },
- ));
+ let elementsPerWorker: number | undefined
+ switch (workerConfiguration.elementsPerWorker) {
+ case 'auto':
+ elementsPerWorker =
+ this.numberOfConfiguredChargingStations > availableParallelism()
+ ? Math.round(this.numberOfConfiguredChargingStations / (availableParallelism() * 1.5))
+ : 1
+ break
+ case 'all':
+ elementsPerWorker = this.numberOfConfiguredChargingStations
+ break
+ }
+ this.workerImplementation = WorkerFactory.getWorkerImplementation<ChargingStationWorkerData>(
+ join(
+ dirname(fileURLToPath(import.meta.url)),
+ `ChargingStationWorker${extname(fileURLToPath(import.meta.url))}`
+ ),
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ workerConfiguration.processType!,
+ {
+ workerStartDelay: workerConfiguration.startDelay,
+ elementStartDelay: workerConfiguration.elementStartDelay,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ poolMaxSize: workerConfiguration.poolMaxSize!,
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ poolMinSize: workerConfiguration.poolMinSize!,
+ elementsPerWorker: elementsPerWorker ?? (workerConfiguration.elementsPerWorker as number),
+ poolOptions: {
+ messageHandler: this.messageHandler.bind(this) as MessageHandler<Worker>,
+ workerOptions: { resourceLimits: workerConfiguration.resourceLimits }
+ }
+ }
+ )