refactor: remove pool strategy from worker configuration section
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 14 Jul 2023 18:49:33 +0000 (20:49 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 14 Jul 2023 18:49:33 +0000 (20:49 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
README.md
src/charging-station/Bootstrap.ts
src/types/ConfigurationData.ts
src/utils/Configuration.ts

index 49fbeb02cc9485bb7ef854bb5a3073046ed3a434..c5f9409f2b2d1766c1b4447898bfd3e7c2082f0b 100644 (file)
--- a/README.md
+++ b/README.md
@@ -105,7 +105,7 @@ But the modifications to test have to be done to the files in the build target d
 | supervisionUrls            |                                              | []                                                                                                                                                                                                                            | string \| string[]                                                                                                                                                                                                                                                 | string or strings array containing global connection URIs to OCPP-J servers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
 | supervisionUrlDistribution | round-robin/random/charging-station-affinity | charging-station-affinity                                                                                                                                                                                                     | string                                                                                                                                                                                                                                                             | supervision urls distribution policy to simulated charging stations                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
 | log                        |                                              | {<br />"enabled": true,<br />"file": "logs/combined.log",<br />"errorFile": "logs/error.log",<br />"statisticsInterval": 60,<br />"level": "info",<br />"console": false,<br />"format": "simple",<br />"rotate": true<br />} | {<br />enabled: boolean;<br />file: string;<br />errorFile: string;<br />statisticsInterval: number;<br />level: string;<br />console: boolean;<br />format: string;<br />rotate: boolean;<br />maxFiles: string \| number;<br />maxSize: string \| number;<br />} | Log configuration section:<br />- _enabled_: enable logging<br />- _file_: log file relative path<br />- _errorFile_: error log file relative path<br />- _statisticsInterval_: seconds between charging stations statistics output in the logs<br />- _level_: emerg/alert/crit/error/warning/notice/info/debug [winston](https://github.com/winstonjs/winston) logging level</br >- _console_: output logs on the console<br />- _format_: [winston](https://github.com/winstonjs/winston) log format<br />- _rotate_: enable daily log files rotation<br />- _maxFiles_: maximum number of log files: https://github.com/winstonjs/winston-daily-rotate-file#options<br />- _maxSize_: maximum size of log files in bytes, or units of kb, mb, and gb: https://github.com/winstonjs/winston-daily-rotate-file#options |
-| worker                     |                                              | {<br />"processType": "workerSet",<br />"startDelay": 500,<br />"elementStartDelay": 0,<br />"elementsPerWorker": 'auto',<br />"poolMinSize": 4,<br />"poolMaxSize": 16,<br />"poolStrategy": "ROUND_ROBIN"<br />}            | {<br />processType: WorkerProcessType;<br />startDelay: number;<br />elementStartDelay: number;<br />elementsPerWorker: number \| 'auto';<br />poolMinSize: number;<br />poolMaxSize: number;<br />poolStrategy: WorkerChoiceStrategy;<br />}                      | Worker configuration section:<br />- _processType_: worker threads process type (`workerSet`/`staticPool`/`dynamicPool`)<br />- _startDelay_: milliseconds to wait at worker threads startup (only for `workerSet` worker threads process type)<br />- _elementStartDelay_: milliseconds to wait at charging station startup<br />- _elementsPerWorker_: number of charging stations per worker threads for the `workerSet` process type (`auto` means (number of stations) / (number of CPUs) if (number of stations) > (number of CPUs), otherwise 1)<br />- _poolMinSize_: worker threads pool minimum number of threads</br >- _poolMaxSize_: worker threads pool maximum number of threads<br />- _poolStrategy_: worker threads pool [poolifier](https://github.com/poolifier/poolifier) worker choice strategy    |
+| worker                     |                                              | {<br />"processType": "workerSet",<br />"startDelay": 500,<br />"elementStartDelay": 0,<br />"elementsPerWorker": 'auto',<br />"poolMinSize": 4,<br />"poolMaxSize": 16}                                                      | {<br />processType: WorkerProcessType;<br />startDelay: number;<br />elementStartDelay: number;<br />elementsPerWorker: number \| 'auto';<br />poolMinSize: number;<br />poolMaxSize: number;<br />}                                                               | Worker configuration section:<br />- _processType_: worker threads process type (`workerSet`/`staticPool`/`dynamicPool`)<br />- _startDelay_: milliseconds to wait at worker threads startup (only for `workerSet` worker threads process type)<br />- _elementStartDelay_: milliseconds to wait at charging station startup<br />- _elementsPerWorker_: number of charging stations per worker threads for the `workerSet` process type (`auto` means (number of stations) / (number of CPUs) if (number of stations) > (number of CPUs), otherwise 1)<br />- _poolMinSize_: worker threads pool minimum number of threads</br >- _poolMaxSize_: worker threads pool maximum number of threads                                                                                                                          |
 | uiServer                   |                                              | {<br />"enabled": false,<br />"type": "ws",<br />"options": {<br />"host": "localhost",<br />"port": 8080<br />}<br />}                                                                                                       | {<br />enabled: boolean;<br />type: ApplicationProtocol;<br />options: ServerOptions;<br />authentication: {<br />enabled: boolean;<br />type: AuthenticationType;<br />username: string;<br />password: string;<br />}<br />}                                     | UI server configuration section                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
 | performanceStorage         |                                              | {<br />"enabled": false,<br />"type": "jsonfile",<br />"file:///performanceRecords.json"<br />}                                                                                                                               | {<br />enabled: boolean;<br />type: string;<br />URI: string;<br />}<br />where type can be 'jsonfile' or 'mongodb'                                                                                                                                                | performance storage configuration section                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
 | stationTemplateUrls        |                                              | {}[]                                                                                                                                                                                                                          | {<br />file: string;<br />numberOfStations: number;<br />}[]                                                                                                                                                                                                       | array of charging station configuration templates URIs configuration section (charging station configuration template file name and number of stations)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
index 1550f6a7dc8ee92547fda280dbe4f569592f753e..13774cc6f5e327c6da52a1031a8e6bbb1ef9e688 100644 (file)
@@ -36,7 +36,7 @@ import {
   logPrefix,
   logger,
 } from '../utils';
-import { type WorkerAbstract, WorkerConstants, WorkerFactory } from '../worker';
+import { type WorkerAbstract, WorkerFactory } from '../worker';
 
 const moduleName = 'Bootstrap';
 
@@ -231,7 +231,6 @@ export class Bootstrap extends EventEmitter {
           elementsPerWorker:
             elementsPerWorker ?? (Configuration.getWorker().elementsPerWorker as number),
           poolOptions: {
-            workerChoiceStrategy: Configuration.getWorker().poolStrategy,
             messageHandler: this.messageHandler.bind(this) as (message: unknown) => void,
           },
         },
index 94ac3b34eb2645c94639b51ff077c4704d2b9292..accdcc2198b05d79c0c9416bc46d28b40a784eee 100644 (file)
@@ -57,6 +57,7 @@ export type WorkerConfiguration = {
   elementStartDelay?: number;
   poolMinSize?: number;
   poolMaxSize?: number;
+  /** @deprecated Not publicly exposed to end users. */
   poolStrategy?: WorkerChoiceStrategy;
 };
 
index 92ce46e359a039ef42080504ddb8c24f7225d37a..691721e939b35bc37998e046eba93500523ef339 100644 (file)
@@ -4,7 +4,6 @@ import { fileURLToPath } from 'node:url';
 
 import chalk from 'chalk';
 import merge from 'just-merge';
-import { WorkerChoiceStrategies } from 'poolifier';
 
 import { Constants } from './Constants';
 import { hasOwnProp, isCFEnvironment, isNotEmptyString, isUndefined } from './Utils';
@@ -292,8 +291,9 @@ export class Configuration {
       elementStartDelay: WorkerConstants.DEFAULT_ELEMENT_START_DELAY,
       poolMinSize: WorkerConstants.DEFAULT_POOL_MIN_SIZE,
       poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE,
-      poolStrategy: WorkerChoiceStrategies.ROUND_ROBIN,
     };
+    hasOwnProp(Configuration.getConfig(), 'workerPoolStrategy') &&
+      delete Configuration.getConfig()?.workerPoolStrategy;
     const deprecatedWorkerConfiguration: WorkerConfiguration = {
       ...(hasOwnProp(Configuration.getConfig(), 'workerProcess') && {
         processType: Configuration.getConfig()?.workerProcess,
@@ -313,11 +313,12 @@ export class Configuration {
       ...(hasOwnProp(Configuration.getConfig(), 'workerPoolMaxSize') && {
         poolMaxSize: Configuration.getConfig()?.workerPoolMaxSize,
       }),
-      ...(hasOwnProp(Configuration.getConfig(), 'workerPoolStrategy') && {
-        poolStrategy:
-          Configuration.getConfig()?.workerPoolStrategy ?? WorkerChoiceStrategies.ROUND_ROBIN,
-      }),
     };
+    Configuration.warnDeprecatedConfigurationKey(
+      'poolStrategy',
+      'worker',
+      'Not publicly exposed to end users',
+    );
     const workerConfiguration: WorkerConfiguration = {
       ...defaultWorkerConfiguration,
       ...deprecatedWorkerConfiguration,