From: Jérôme Benoit Date: Sun, 23 Jul 2023 20:27:40 +0000 (+0200) Subject: perf: fine tune default pool size for load tests X-Git-Tag: v1.2.20~164 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c7db8ecb3b71cbc4f6e0458c63c0aee37d720acf;p=e-mobility-charging-stations-simulator.git perf: fine tune default pool size for load tests Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 79d9a008..16a590a9 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -230,7 +230,7 @@ export class Bootstrap extends EventEmitter { if (workerConfiguration?.elementsPerWorker === 'auto') { elementsPerWorker = this.numberOfChargingStations > availableParallelism() - ? Math.round(this.numberOfChargingStations / availableParallelism()) + ? Math.round(this.numberOfChargingStations / (availableParallelism() * 1.5)) : 1; } this.workerImplementation === null && diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index a0dd92ba..dfe67377 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -177,6 +177,7 @@ export class ChargingStation { private configurationFileHash!: string; private connectorsConfigurationHash!: string; private evsesConfigurationHash!: string; + private automaticTransactionGeneratorConfiguration?: AutomaticTransactionGeneratorConfiguration; private ocppIncomingRequestService!: OCPPIncomingRequestService; private readonly messageBuffer: Set; private configuredSupervisionUrl!: URL; @@ -688,6 +689,7 @@ export class ChargingStation { // Initialize this.initialize(); this.idTagsCache.deleteIdTags(getIdTagsFile(this.stationInfo)!); + delete this.automaticTransactionGeneratorConfiguration; // Restart the ATG this.stopAutomaticTransactionGenerator(); if (this.getAutomaticTransactionGeneratorConfiguration()?.enable === true) { @@ -846,25 +848,28 @@ export class ChargingStation { } public getAutomaticTransactionGeneratorConfiguration(): AutomaticTransactionGeneratorConfiguration { - let automaticTransactionGeneratorConfiguration: - | AutomaticTransactionGeneratorConfiguration - | undefined; - const automaticTransactionGeneratorConfigurationFromFile = - this.getConfigurationFromFile()?.automaticTransactionGenerator; - if ( - this.getAutomaticTransactionGeneratorPersistentConfiguration() && - automaticTransactionGeneratorConfigurationFromFile - ) { - automaticTransactionGeneratorConfiguration = - automaticTransactionGeneratorConfigurationFromFile; - } else { - automaticTransactionGeneratorConfiguration = - this.getTemplateFromFile()?.AutomaticTransactionGenerator; + if (isNullOrUndefined(this.automaticTransactionGeneratorConfiguration)) { + let automaticTransactionGeneratorConfiguration: + | AutomaticTransactionGeneratorConfiguration + | undefined; + const automaticTransactionGeneratorConfigurationFromFile = + this.getConfigurationFromFile()?.automaticTransactionGenerator; + if ( + this.getAutomaticTransactionGeneratorPersistentConfiguration() && + automaticTransactionGeneratorConfigurationFromFile + ) { + automaticTransactionGeneratorConfiguration = + automaticTransactionGeneratorConfigurationFromFile; + } else { + automaticTransactionGeneratorConfiguration = + this.getTemplateFromFile()?.AutomaticTransactionGenerator; + } + this.automaticTransactionGeneratorConfiguration = { + ...Constants.DEFAULT_ATG_CONFIGURATION, + ...automaticTransactionGeneratorConfiguration, + }; } - return { - ...Constants.DEFAULT_ATG_CONFIGURATION, - ...automaticTransactionGeneratorConfiguration, - }; + return this.automaticTransactionGeneratorConfiguration!; } public getAutomaticTransactionGeneratorStatuses(): Status[] | undefined { diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index cbc9f20d..f03e0472 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -35,8 +35,8 @@ export class Configuration { 'config.json', ); - private static configurationFileWatcher: FSWatcher | undefined; - private static configurationData: ConfigurationData | null = null; + private static configurationFileWatcher?: FSWatcher; + private static configurationData?: ConfigurationData; private static configurationSectionCache = new Map< ConfigurationSection, ConfigurationSectionType @@ -481,7 +481,7 @@ export class Configuration { } } - private static getConfigurationData(): ConfigurationData | null { + private static getConfigurationData(): ConfigurationData | undefined { if (!Configuration.configurationData) { try { Configuration.configurationData = JSON.parse( @@ -506,8 +506,7 @@ export class Configuration { try { return watch(Configuration.configurationFile, (event, filename): void => { if (filename!.trim()!.length > 0 && event === 'change') { - // Nullify to force configuration file reading - Configuration.configurationData = null; + delete Configuration.configurationData; Configuration.configurationSectionCache.clear(); if (!isUndefined(Configuration.configurationChangeCallback)) { Configuration.configurationChangeCallback().catch((error) => { diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 36b23fb1..dcbe2ca4 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -9,7 +9,7 @@ export class WorkerConstants { public static readonly DEFAULT_WORKER_START_DELAY = 500; public static readonly POOL_MAX_INACTIVE_TIME = 60000; public static readonly DEFAULT_POOL_MIN_SIZE = Math.floor(availableParallelism() / 2); - public static readonly DEFAULT_POOL_MAX_SIZE = availableParallelism(); + public static readonly DEFAULT_POOL_MAX_SIZE = Math.round(availableParallelism() * 1.5); public static readonly DEFAULT_ELEMENTS_PER_WORKER = 1; public static readonly version = '1.0.1';