From: Jérôme Benoit Date: Tue, 19 Mar 2024 15:21:32 +0000 (+0100) Subject: refactor: rename configuration elementStartDelay to elementAddDelay X-Git-Tag: v1.3.1~33 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=da47bc294fb5e439e96faaf9441ba0cd23e64f9c;p=e-mobility-charging-stations-simulator.git refactor: rename configuration elementStartDelay to elementAddDelay The start and the add ops have been untangled Signed-off-by: Jérôme Benoit --- diff --git a/README.md b/README.md index 1193489b..739f33f3 100644 --- a/README.md +++ b/README.md @@ -137,15 +137,15 @@ But the modifications to test have to be done to the files in the build target d **src/assets/config.json**: -| Key | Value(s) | Default Value | Value type | Description | -| -------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| 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 | | {
"enabled": true,
"file": "logs/combined.log",
"errorFile": "logs/error.log",
"statisticsInterval": 60,
"level": "info",
"console": false,
"format": "simple",
"rotate": true
} | {
enabled?: boolean;
file?: string;
errorFile?: string;
statisticsInterval?: number;
level?: string;
console?: boolean;
format?: string;
rotate?: boolean;
maxFiles?: string \| number;
maxSize?: string \| number;
} | Log configuration section:
- _enabled_: enable logging
- _file_: log file relative path
- _errorFile_: error log file relative path
- _statisticsInterval_: seconds between charging stations statistics output in the logs
- _level_: emerg/alert/crit/error/warning/notice/info/debug [winston](https://github.com/winstonjs/winston) logging level
- _console_: output logs on the console
- _format_: [winston](https://github.com/winstonjs/winston) log format
- _rotate_: enable daily log files rotation
- _maxFiles_: maximum number of log files: https://github.com/winstonjs/winston-daily-rotate-file#options
- _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 | | {
"processType": "workerSet",
"startDelay": 500,
"elementStartDelay": 0,
"elementsPerWorker": 'auto',
"poolMinSize": 4,
"poolMaxSize": 16
} | {
processType?: WorkerProcessType;
startDelay?: number;
elementStartDelay?: number;
elementsPerWorker?: number \| 'auto' \| 'all';
poolMinSize?: number;
poolMaxSize?: number;
resourceLimits?: ResourceLimits;
} | Worker configuration section:
- _processType_: worker threads process type (`workerSet`/`fixedPool`/`dynamicPool`)
- _startDelay_: milliseconds to wait at worker threads startup (only for `workerSet` worker threads process type)
- _elementStartDelay_: milliseconds to wait at charging station startup
- _elementsPerWorker_: number of charging stations per worker threads for the `workerSet` process type (`auto` means (number of stations) / (number of CPUs) \* 1.5 if (number of stations) > (number of CPUs), otherwise 1; `all` means a unique worker will run all charging stations)
- _poolMinSize_: worker threads pool minimum number of threads
- _poolMaxSize_: worker threads pool maximum number of threads
- _resourceLimits_: worker threads [resource limits](https://nodejs.org/api/worker_threads.html#new-workerfilename-options) object option | -| uiServer | | {
"enabled": false,
"type": "ws",
"version": "1.1",
"options": {
"host": "localhost",
"port": 8080
}
} | {
enabled?: boolean;
type?: ApplicationProtocol;
version?: ApplicationProtocolVersion;
options?: ServerOptions;
authentication?: {
enabled: boolean;
type: AuthenticationType;
username?: string;
password?: string;
}
} | UI server configuration section:
- _enabled_: enable UI server
- _type_: 'http' or 'ws'
- _version_: HTTP version '1.1' or '2.0'
- _options_: node.js net module [listen options](https://nodejs.org/api/net.html#serverlistenoptions-callback)
- _authentication_: authentication type configuration section | -| performanceStorage | | {
"enabled": true,
"type": "none",
} | {
enabled?: boolean;
type?: string;
uri?: string;
} | Performance storage configuration section:
- _enabled_: enable performance storage
- _type_: 'jsonfile', 'mongodb' or 'none'
- _uri_: storage URI | -| stationTemplateUrls | | {}[] | {
file: string;
numberOfStations: number;
}[] | array of charging station configuration templates URIs configuration section (charging station configuration template file name and number of stations) | +| Key | Value(s) | Default Value | Value type | Description | +| -------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 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 | | {
"enabled": true,
"file": "logs/combined.log",
"errorFile": "logs/error.log",
"statisticsInterval": 60,
"level": "info",
"console": false,
"format": "simple",
"rotate": true
} | {
enabled?: boolean;
file?: string;
errorFile?: string;
statisticsInterval?: number;
level?: string;
console?: boolean;
format?: string;
rotate?: boolean;
maxFiles?: string \| number;
maxSize?: string \| number;
} | Log configuration section:
- _enabled_: enable logging
- _file_: log file relative path
- _errorFile_: error log file relative path
- _statisticsInterval_: seconds between charging stations statistics output in the logs
- _level_: emerg/alert/crit/error/warning/notice/info/debug [winston](https://github.com/winstonjs/winston) logging level
- _console_: output logs on the console
- _format_: [winston](https://github.com/winstonjs/winston) log format
- _rotate_: enable daily log files rotation
- _maxFiles_: maximum number of log files: https://github.com/winstonjs/winston-daily-rotate-file#options
- _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 | | {
"processType": "workerSet",
"startDelay": 500,
"elementAddDelay": 0,
"elementsPerWorker": 'auto',
"poolMinSize": 4,
"poolMaxSize": 16
} | {
processType?: WorkerProcessType;
startDelay?: number;
elementAddDelay?: number;
elementsPerWorker?: number \| 'auto' \| 'all';
poolMinSize?: number;
poolMaxSize?: number;
resourceLimits?: ResourceLimits;
} | Worker configuration section:
- _processType_: worker threads process type (`workerSet`/`fixedPool`/`dynamicPool`)
- _startDelay_: milliseconds to wait at worker threads startup (only for `workerSet` worker threads process type)
- _elementAddDelay_: milliseconds to wait between charging station add
- _elementsPerWorker_: number of charging stations per worker threads for the `workerSet` process type (`auto` means (number of stations) / (number of CPUs) \* 1.5 if (number of stations) > (number of CPUs), otherwise 1; `all` means a unique worker will run all charging stations)
- _poolMinSize_: worker threads pool minimum number of threads
- _poolMaxSize_: worker threads pool maximum number of threads
- _resourceLimits_: worker threads [resource limits](https://nodejs.org/api/worker_threads.html#new-workerfilename-options) object option | +| uiServer | | {
"enabled": false,
"type": "ws",
"version": "1.1",
"options": {
"host": "localhost",
"port": 8080
}
} | {
enabled?: boolean;
type?: ApplicationProtocol;
version?: ApplicationProtocolVersion;
options?: ServerOptions;
authentication?: {
enabled: boolean;
type: AuthenticationType;
username?: string;
password?: string;
}
} | UI server configuration section:
- _enabled_: enable UI server
- _type_: 'http' or 'ws'
- _version_: HTTP version '1.1' or '2.0'
- _options_: node.js net module [listen options](https://nodejs.org/api/net.html#serverlistenoptions-callback)
- _authentication_: authentication type configuration section | +| performanceStorage | | {
"enabled": true,
"type": "none",
} | {
enabled?: boolean;
type?: string;
uri?: string;
} | Performance storage configuration section:
- _enabled_: enable performance storage
- _type_: 'jsonfile', 'mongodb' or 'none'
- _uri_: storage URI | +| stationTemplateUrls | | {}[] | {
file: string;
numberOfStations: number;
}[] | array of charging station configuration templates URIs configuration section (charging station configuration template file name and number of stations) | #### Worker process model diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index ad8c9b0c..545e8889 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -348,7 +348,7 @@ export class Bootstrap extends EventEmitter { workerConfiguration.processType!, { workerStartDelay: workerConfiguration.startDelay, - elementStartDelay: workerConfiguration.elementStartDelay, + elementAddDelay: workerConfiguration.elementAddDelay, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion poolMaxSize: workerConfiguration.poolMaxSize!, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion diff --git a/src/types/ChargingStationInfo.ts b/src/types/ChargingStationInfo.ts index 4ebdc150..12327cd8 100644 --- a/src/types/ChargingStationInfo.ts +++ b/src/types/ChargingStationInfo.ts @@ -17,7 +17,7 @@ ChargingStationTemplate, hashId: string templateIndex: number templateName: string - /** @deprecated Use hashId instead */ + /** @deprecated Use `hashId` instead. */ infoHash?: string chargingStationId?: string chargeBoxSerialNumber?: string diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index d20dfdc1..b3cc7734 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -111,9 +111,9 @@ export interface ChargingStationTemplate { registrationMaxRetries?: number enableStatistics?: boolean remoteAuthorization?: boolean - /** @deprecated Replaced by remoteAuthorization */ + /** @deprecated Replaced by remoteAuthorization. */ mustAuthorizeAtRemoteStart?: boolean - /** @deprecated Replaced by ocppStrictCompliance */ + /** @deprecated Replaced by ocppStrictCompliance. */ payloadSchemaValidation?: boolean amperageLimitationOcppKey?: string amperageLimitationUnit?: AmpereUnits diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index 3248ec55..3d5f98a7 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -70,7 +70,9 @@ export interface WorkerConfiguration { processType?: WorkerProcessType startDelay?: number elementsPerWorker?: ElementsPerWorkerType + /** @deprecated Use `elementAddDelay` instead. */ elementStartDelay?: number + elementAddDelay?: number poolMinSize?: number poolMaxSize?: number resourceLimits?: ResourceLimits @@ -84,14 +86,14 @@ export interface ConfigurationData { worker?: WorkerConfiguration uiServer?: UIServerConfiguration performanceStorage?: StorageConfiguration - /** @deprecated Moved to charging station template */ + /** @deprecated Moved to charging station template. */ autoReconnectMaxRetries?: number /** @deprecated Moved to worker configuration section. */ workerProcess?: WorkerProcessType /** @deprecated Moved to worker configuration section. */ workerStartDelay?: number /** @deprecated Moved to worker configuration section. */ - elementStartDelay?: number + elementAddDelay?: number /** @deprecated Moved to worker configuration section. */ workerPoolMinSize?: number /** @deprecated Moved to worker configuration section. */ diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index dee8056c..e1fd11c7 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -21,7 +21,7 @@ import { type WorkerConfiguration } from '../types/index.js' import { - DEFAULT_ELEMENT_START_DELAY, + DEFAULT_ELEMENT_ADD_DELAY, DEFAULT_POOL_MAX_SIZE, DEFAULT_POOL_MIN_SIZE, DEFAULT_WORKER_START_DELAY, @@ -275,10 +275,11 @@ export class Configuration { processType: WorkerProcessType.workerSet, startDelay: DEFAULT_WORKER_START_DELAY, elementsPerWorker: 'auto', - elementStartDelay: DEFAULT_ELEMENT_START_DELAY, + elementAddDelay: DEFAULT_ELEMENT_ADD_DELAY, poolMinSize: DEFAULT_POOL_MIN_SIZE, poolMaxSize: DEFAULT_POOL_MAX_SIZE } + const deprecatedWorkerConfiguration: WorkerConfiguration = { ...(hasOwnProp(Configuration.getConfigurationData(), 'workerProcess') && { processType: Configuration.getConfigurationData()?.workerProcess @@ -289,8 +290,11 @@ export class Configuration { ...(hasOwnProp(Configuration.getConfigurationData(), 'chargingStationsPerWorker') && { elementsPerWorker: Configuration.getConfigurationData()?.chargingStationsPerWorker }), - ...(hasOwnProp(Configuration.getConfigurationData(), 'elementStartDelay') && { - elementStartDelay: Configuration.getConfigurationData()?.elementStartDelay + ...(hasOwnProp(Configuration.getConfigurationData(), 'elementAddDelay') && { + elementAddDelay: Configuration.getConfigurationData()?.elementAddDelay + }), + ...(hasOwnProp(Configuration.getConfigurationData()?.worker, 'elementStartDelay') && { + elementAddDelay: Configuration.getConfigurationData()?.worker?.elementStartDelay }), ...(hasOwnProp(Configuration.getConfigurationData(), 'workerPoolMinSize') && { poolMinSize: Configuration.getConfigurationData()?.workerPoolMinSize @@ -396,9 +400,9 @@ export class Configuration { `Use '${ConfigurationSection.worker}' section to define the number of element(s) per worker instead` ) Configuration.warnDeprecatedConfigurationKey( - 'elementStartDelay', + 'elementAddDelay', undefined, - `Use '${ConfigurationSection.worker}' section to define the worker's element start delay instead` + `Use '${ConfigurationSection.worker}' section to define the worker's element add delay instead` ) Configuration.warnDeprecatedConfigurationKey( 'workerPoolMinSize', @@ -425,6 +429,11 @@ export class Configuration { ConfigurationSection.worker, 'Not publicly exposed to end users' ) + Configuration.warnDeprecatedConfigurationKey( + 'elementStartDelay', + ConfigurationSection.worker, + "Use 'elementAddDelay' instead" + ) if ( Configuration.getConfigurationData()?.worker?.processType === ('staticPool' as WorkerProcessType) diff --git a/src/worker/WorkerConstants.ts b/src/worker/WorkerConstants.ts index 40484095..28e9927d 100644 --- a/src/worker/WorkerConstants.ts +++ b/src/worker/WorkerConstants.ts @@ -9,7 +9,7 @@ export const EMPTY_FUNCTION = Object.freeze(() => { export const workerSetVersion = '1.0.1' -export const DEFAULT_ELEMENT_START_DELAY = 0 +export const DEFAULT_ELEMENT_ADD_DELAY = 0 export const DEFAULT_WORKER_START_DELAY = 500 export const DEFAULT_POOL_MIN_SIZE = Math.floor(availableParallelism() / 2) export const DEFAULT_POOL_MAX_SIZE = Math.round(availableParallelism() * 1.5) @@ -17,7 +17,7 @@ export const DEFAULT_ELEMENTS_PER_WORKER = 1 export const DEFAULT_WORKER_OPTIONS: WorkerOptions = Object.freeze({ workerStartDelay: DEFAULT_WORKER_START_DELAY, - elementStartDelay: DEFAULT_ELEMENT_START_DELAY, + elementAddDelay: DEFAULT_ELEMENT_ADD_DELAY, poolMinSize: DEFAULT_POOL_MIN_SIZE, poolMaxSize: DEFAULT_POOL_MAX_SIZE, elementsPerWorker: DEFAULT_ELEMENTS_PER_WORKER, diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index 817536f0..0bdb2619 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -56,8 +56,8 @@ export class WorkerDynamicPool extends WorkerAbstract { await this.pool.execute(elementData) // Start element sequentially to optimize memory at startup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.workerOptions.elementStartDelay! > 0 && + this.workerOptions.elementAddDelay! > 0 && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - (await sleep(randomizeDelay(this.workerOptions.elementStartDelay!))) + (await sleep(randomizeDelay(this.workerOptions.elementAddDelay!))) } } diff --git a/src/worker/WorkerFixedPool.ts b/src/worker/WorkerFixedPool.ts index 83669041..4eafa1d5 100644 --- a/src/worker/WorkerFixedPool.ts +++ b/src/worker/WorkerFixedPool.ts @@ -55,8 +55,8 @@ export class WorkerFixedPool extends WorkerAbstract { await this.pool.execute(elementData) // Start element sequentially to optimize memory at startup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.workerOptions.elementStartDelay! > 0 && + this.workerOptions.elementAddDelay! > 0 && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - (await sleep(randomizeDelay(this.workerOptions.elementStartDelay!))) + (await sleep(randomizeDelay(this.workerOptions.elementAddDelay!))) } } diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index b4a1ec20..1ad551ef 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -115,9 +115,9 @@ export class WorkerSet extends WorkerAbstract { ++workerSetElement.numberOfWorkerElements // Add element sequentially to optimize memory at startup // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - if (this.workerOptions.elementStartDelay! > 0) { + if (this.workerOptions.elementAddDelay! > 0) { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - await sleep(randomizeDelay(this.workerOptions.elementStartDelay!)) + await sleep(randomizeDelay(this.workerOptions.elementAddDelay!)) } } diff --git a/src/worker/WorkerTypes.ts b/src/worker/WorkerTypes.ts index 5c8c177f..ee69c191 100644 --- a/src/worker/WorkerTypes.ts +++ b/src/worker/WorkerTypes.ts @@ -36,7 +36,7 @@ export type WorkerEvents = PoolEvent | WorkerSetEvents export interface WorkerOptions { workerStartDelay?: number - elementStartDelay?: number + elementAddDelay?: number poolMaxSize: number poolMinSize: number elementsPerWorker?: number diff --git a/src/worker/index.ts b/src/worker/index.ts index 878ef686..649e0c62 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -1,6 +1,6 @@ export type { WorkerAbstract } from './WorkerAbstract.js' export { - DEFAULT_ELEMENT_START_DELAY, + DEFAULT_ELEMENT_ADD_DELAY, DEFAULT_POOL_MAX_SIZE, DEFAULT_POOL_MIN_SIZE, DEFAULT_WORKER_START_DELAY