perf: fine tune default pool size for load tests
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 23 Jul 2023 20:27:40 +0000 (22:27 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 23 Jul 2023 20:27:40 +0000 (22:27 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts
src/charging-station/ChargingStation.ts
src/utils/Configuration.ts
src/worker/WorkerConstants.ts

index 79d9a00865c4a0d3ae9368f7c21a141e39ac4fd3..16a590a9a493193c9dd7d4ede7789b6f4c8a2cfa 100644 (file)
@@ -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 &&
index a0dd92ba4641a7dd0709b8ab6d3abb90174cd8c7..dfe6737713da6ab12964352884ec03d512e0e377 100644 (file)
@@ -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<string>;
   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 {
index cbc9f20d4125a6a562444dddd22860e68cded900..f03e0472570ec0af65a1a0dd070d57a8131fd911 100644 (file)
@@ -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) => {
index 36b23fb15a76a009141bbfe64cde7f224771a503..dcbe2ca43caa3faec645c6e693dc04f1cb8b93f2 100644 (file)
@@ -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';