From 8f8f87c4fd9a0863d0aeb4a9a8671d1a2b4308e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 26 Mar 2024 20:23:20 +0100 Subject: [PATCH] feat: allow to provision number of stations by template MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 2 +- src/assets/config-template.json | 3 ++- src/charging-station/Bootstrap.ts | 27 ++++++++++++++++++++------ src/charging-station/SharedLRUCache.ts | 3 ++- src/types/ConfigurationData.ts | 1 + src/types/SimulatorState.ts | 2 ++ src/types/Statistics.ts | 1 + src/utils/Configuration.ts | 2 +- 8 files changed, 31 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index e897431b..7445d387 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ But the modifications to test have to be done to the files in the build target d | 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) | +| stationTemplateUrls | | {}[] | {
file: string;
numberOfStations: number;
provisionedNumberOfStations?: number;
}[] | array of charging station templates URIs configuration section:
- _file_: charging station configuration template file relative path
- _numberOfStations_: template number of stations at startup
- _provisionedNumberOfStations_: template provisioned number of stations after startup | #### Worker process model diff --git a/src/assets/config-template.json b/src/assets/config-template.json index 0946258f..943e9c5b 100644 --- a/src/assets/config-template.json +++ b/src/assets/config-template.json @@ -31,7 +31,8 @@ }, { "file": "keba.station-template.json", - "numberOfStations": 2 + "numberOfStations": 2, + "provisionedNumberOfStations": 2 }, { "file": "abb.station-template.json", diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index bb801e74..5293a9a8 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -114,9 +114,17 @@ export class Bootstrap extends EventEmitter { ) } + public get numberOfProvisionedChargingStations (): number { + return [...this.templateStatistics.values()].reduce( + (accumulator, value) => accumulator + value.provisioned, + 0 + ) + } + public getState (): SimulatorState { return { version: this.version, + configuration: Configuration.getConfigurationData(), started: this.started, templateStatistics: this.templateStatistics } @@ -219,7 +227,7 @@ export class Bootstrap extends EventEmitter { chalk.green( `Charging stations simulator ${ this.version - } started with ${this.numberOfConfiguredChargingStations} configured charging station(s) from ${this.numberOfChargingStationTemplates} charging station template(s) and ${ + } started with ${this.numberOfConfiguredChargingStations} configured and ${this.numberOfProvisionedChargingStations} provisioned charging station(s) from ${this.numberOfChargingStationTemplates} charging station template(s) and ${ Configuration.workerDynamicPoolInUse() ? `${workerConfiguration.poolMinSize}/` : '' }${this.workerImplementation?.size}${ Configuration.workerPoolInUse() ? `/${workerConfiguration.poolMaxSize}` : '' @@ -327,12 +335,18 @@ export class Bootstrap extends EventEmitter { let elementsPerWorker: number switch (workerConfiguration.elementsPerWorker) { case 'all': - elementsPerWorker = this.numberOfConfiguredChargingStations + elementsPerWorker = + this.numberOfConfiguredChargingStations + this.numberOfProvisionedChargingStations break case 'auto': elementsPerWorker = - this.numberOfConfiguredChargingStations > availableParallelism() - ? Math.round(this.numberOfConfiguredChargingStations / (availableParallelism() * 1.5)) + this.numberOfConfiguredChargingStations + this.numberOfProvisionedChargingStations > + availableParallelism() + ? Math.round( + (this.numberOfConfiguredChargingStations + + this.numberOfProvisionedChargingStations) / + (availableParallelism() * 1.5) + ) : 1 break default: @@ -422,7 +436,7 @@ export class Bootstrap extends EventEmitter { data.stationInfo.chargingStationId } (hashId: ${data.stationInfo.hashId}) added (${ this.numberOfAddedChargingStations - } added from ${this.numberOfConfiguredChargingStations} configured charging station(s))` + } added from ${this.numberOfConfiguredChargingStations} configured and ${this.numberOfProvisionedChargingStations} provisioned charging station(s))` ) } @@ -437,7 +451,7 @@ export class Bootstrap extends EventEmitter { data.stationInfo.chargingStationId } (hashId: ${data.stationInfo.hashId}) deleted (${ this.numberOfAddedChargingStations - } added from ${this.numberOfConfiguredChargingStations} configured charging station(s))` + } added from ${this.numberOfConfiguredChargingStations} configured and ${this.numberOfProvisionedChargingStations} provisioned charging station(s))` ) } @@ -494,6 +508,7 @@ export class Bootstrap extends EventEmitter { const templateName = buildTemplateName(stationTemplateUrl.file) this.templateStatistics.set(templateName, { configured: stationTemplateUrl.numberOfStations, + provisioned: stationTemplateUrl.provisionedNumberOfStations ?? 0, added: 0, started: 0, indexes: new Set() diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 7f459a4f..0da4558d 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -19,7 +19,8 @@ export class SharedLRUCache { private constructor () { this.lruCache = new LRUCache( Bootstrap.getInstance().numberOfChargingStationTemplates + - Bootstrap.getInstance().numberOfConfiguredChargingStations + Bootstrap.getInstance().numberOfConfiguredChargingStations + + Bootstrap.getInstance().numberOfProvisionedChargingStations ) } diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index 3d5f98a7..ffbb7dec 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -25,6 +25,7 @@ export enum SupervisionUrlDistribution { export interface StationTemplateUrl { file: string numberOfStations: number + provisionedNumberOfStations?: number } export interface LogConfiguration { diff --git a/src/types/SimulatorState.ts b/src/types/SimulatorState.ts index d3816ede..0ba53078 100644 --- a/src/types/SimulatorState.ts +++ b/src/types/SimulatorState.ts @@ -1,7 +1,9 @@ +import type { ConfigurationData } from './ConfigurationData.js' import type { TemplateStatistics } from './Statistics.js' export interface SimulatorState { version: string + configuration: ConfigurationData | undefined started: boolean templateStatistics: Map } diff --git a/src/types/Statistics.ts b/src/types/Statistics.ts index 81ba1d56..4c03dd9d 100644 --- a/src/types/Statistics.ts +++ b/src/types/Statistics.ts @@ -34,6 +34,7 @@ export interface Statistics extends WorkerData { export interface TemplateStatistics { configured: number + provisioned: number added: number started: number indexes: Set diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 9356785d..25a1475b 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -544,7 +544,7 @@ export class Configuration { } } - private static getConfigurationData (): ConfigurationData | undefined { + public static getConfigurationData (): ConfigurationData | undefined { if (Configuration.configurationData == null) { try { Configuration.configurationData = JSON.parse( -- 2.34.1