"kuler": "^2.0.0"
}
},
+ "@es-joy/jsdoccomment": {
+ "version": "0.1.1",
+ "resolved": "https://registry.npmjs.org/@es-joy/jsdoccomment/-/jsdoccomment-0.1.1.tgz",
+ "integrity": "sha512-6lIx5Pjc50D7VJU9lfRZ1twfIrIwQk+aeT9Ink2C07IUu/y9pxkIpDqmhY/VN3jAW42dA5z6ioOdyhOZZU1isw==",
+ "dev": true
+ },
"@eslint/eslintrc": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-0.4.0.tgz",
}
},
"eslint-plugin-jsdoc": {
- "version": "32.3.3",
- "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-32.3.3.tgz",
- "integrity": "sha512-WxXohbMYlZvCt3r7MepwT++nTLsO4CPegWcm5toM4IGq3MBmYkG+Uf5yDa+n1MwPXLg+KbJqAsI19hmkVD7MPg==",
+ "version": "33.0.0",
+ "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-33.0.0.tgz",
+ "integrity": "sha512-bkopnnuDdT04abKWPfDdD6XcAp2yX6UDpDViyvIdYmxbZYbpHXCRzQzLqCTo+SzWSTS0KFWz/V3shmmMr+x4EA==",
"dev": true,
"requires": {
+ "@es-joy/jsdoccomment": "^0.1.1",
"comment-parser": "1.1.5",
"debug": "^4.3.1",
"jsdoctypeparser": "^9.0.0",
"cross-env": "^7.0.3",
"eslint": "^7.25.0",
"eslint-plugin-import": "^2.22.1",
- "eslint-plugin-jsdoc": "^32.3.3",
+ "eslint-plugin-jsdoc": "^33.0.0",
"mbt": "^1.1.1",
"npm-check": "^5.9.2",
"rollup": "^2.46.0",
private getWorkerImplementationInstance(): WorkerAbstract {
if (!this.workerImplementationInstance) {
- this.workerImplementationInstance = WorkerFactory.getWorkerImplementation<StationWorkerData>(this.workerScript, Configuration.getWorkerProcess(), {
- poolMaxSize: Configuration.getWorkerPoolMaxSize(),
- poolMinSize: Configuration.getWorkerPoolMinSize(),
- elementsPerWorker: Configuration.getChargingStationsPerWorker()
- });
+ this.workerImplementationInstance = WorkerFactory.getWorkerImplementation<StationWorkerData>(this.workerScript, Configuration.getWorkerProcess(),
+ {
+ startDelay: Configuration.getWorkerStartDelay(),
+ poolMaxSize: Configuration.getWorkerPoolMaxSize(),
+ poolMinSize: Configuration.getWorkerPoolMinSize(),
+ elementsPerWorker: Configuration.getChargingStationsPerWorker()
+ });
}
return this.workerImplementationInstance;
}
autoReconnectMaxRetries?: number;
distributeStationsToTenantsEqually?: boolean;
workerProcess?: WorkerProcessType;
+ workerStartDelay?: number;
workerPoolMinSize?: number;
workerPoolMaxSize?: number;
chargingStationsPerWorker?: number;
}
export interface WorkerOptions {
+ startDelay?: number;
poolMaxSize?: number;
poolMinSize?: number;
elementsPerWorker?: number;
}
-export interface WorkerData { }
+// eslint-disable-next-line @typescript-eslint/no-empty-interface
+export interface WorkerData {}
export interface StationWorkerData extends WorkerData {
index: number;
import ConfigurationData, { StationTemplateURL } from '../types/ConfigurationData';
+import Constants from './Constants';
import { WorkerProcessType } from '../types/Worker';
import fs from 'fs';
import path from 'path';
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerProcess') ? Configuration.getConfig().workerProcess : WorkerProcessType.WORKER_SET;
}
+ static getWorkerStartDelay(): number {
+ return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerStartDelay') ? Configuration.getConfig().workerStartDelay : Constants.WORKER_START_DELAY;
+ }
+
static getWorkerPoolMinSize(): number {
return Configuration.objectHasOwnProperty(Configuration.getConfig(), 'workerPoolMinSize') ? Configuration.getConfig().workerPoolMinSize : 4;
}
static readonly TRANSACTION_DEFAULT_TAGID = '00000000';
- static readonly START_WORKER_DELAY = 500;
+ static readonly WORKER_START_DELAY = 500;
static readonly WORKER_POOL_MAX_INACTIVE_TIME = 60000;
}
+import Constants from '../utils/Constants';
import { WorkerData } from '../types/Worker';
export default abstract class WorkerAbstract {
- protected workerScript: string;
+ protected readonly workerScript: string;
+ protected readonly workerStartDelay: number;
public abstract size: number;
public abstract maxElementsPerWorker: number;
* `WorkerAbstract` constructor.
*
* @param {string} workerScript
+ * @param {number} workerStartDelay
*/
- constructor(workerScript: string) {
+ constructor(workerScript: string, workerStartDelay: number = Constants.WORKER_START_DELAY) {
this.workerScript = workerScript;
+ this.workerStartDelay = workerStartDelay;
}
public abstract start(): Promise<void>;
import { DynamicThreadPool, PoolOptions } from 'poolifier';
-import Constants from '../utils/Constants';
import Utils from '../utils/Utils';
import { Worker } from 'worker_threads';
import WorkerAbstract from './WorkerAbstract';
* @param {string} workerScript
* @param {number} min
* @param {number} max
+ * @param {number} workerStartDelay
*/
- constructor(workerScript: string, min: number, max: number,) {
- super(workerScript);
+ constructor(workerScript: string, min: number, max: number, workerStartDelay?: number) {
+ super(workerScript, workerStartDelay);
this.pool = DynamicPool.getInstance(min, max, this.workerScript);
}
public async addElement(elementData: T): Promise<void> {
await this.pool.execute(elementData);
// Start worker sequentially to optimize memory at startup
- await Utils.sleep(Constants.START_WORKER_DELAY);
+ await Utils.sleep(this.workerStartDelay);
}
}
import { WorkerOptions, WorkerProcessType } from '../types/Worker';
-import Utils from '../utils/Utils';
+import Constants from '../utils/Constants';
import WorkerAbstract from './WorkerAbstract';
import WorkerDynamicPool from './WorkerDynamicPool';
import WorkerSet from './WorkerSet';
if (!isMainThread) {
throw new Error('Trying to get a worker implementation outside the main thread');
}
- if (Utils.isUndefined(options)) {
- options = {} as WorkerOptions;
- }
+ options = options ?? {} as WorkerOptions;
+ options.startDelay = options.startDelay ?? Constants.WORKER_START_DELAY;
switch (workerProcessType) {
case WorkerProcessType.WORKER_SET:
options.elementsPerWorker = options.elementsPerWorker ?? 1;
- return new WorkerSet<T>(workerScript, options.elementsPerWorker);
+ return new WorkerSet<T>(workerScript, options.elementsPerWorker, options.startDelay);
case WorkerProcessType.STATIC_POOL:
options.poolMaxSize = options.poolMaxSize ?? 16;
- return new WorkerStaticPool<T>(workerScript, options.poolMaxSize);
+ return new WorkerStaticPool<T>(workerScript, options.poolMaxSize, options.startDelay);
case WorkerProcessType.DYNAMIC_POOL:
options.poolMinSize = options.poolMinSize ?? 4;
options.poolMaxSize = options.poolMaxSize ?? 16;
- return new WorkerDynamicPool<T>(workerScript, options.poolMinSize, options.poolMaxSize);
+ return new WorkerDynamicPool<T>(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay);
default:
return null;
}
import { WorkerEvents, WorkerSetElement } from '../types/Worker';
-import Constants from '../utils/Constants';
import Utils from '../utils/Utils';
import { Worker } from 'worker_threads';
import WorkerAbstract from './WorkerAbstract';
*
* @param {string} workerScript
* @param {number} maxElementsPerWorker
+ * @param {number} workerStartDelay
*/
- constructor(workerScript: string, maxElementsPerWorker = 1) {
- super(workerScript);
+ constructor(workerScript: string, maxElementsPerWorker = 1, workerStartDelay?: number) {
+ super(workerScript, workerStartDelay);
this.workerSet = new Set<WorkerSetElement>();
this.maxElementsPerWorker = maxElementsPerWorker;
}
if (this.getLastWorkerSetElement().numberOfWorkerElements >= this.maxElementsPerWorker) {
this.startWorker();
// Start worker sequentially to optimize memory at startup
- await Utils.sleep(Constants.START_WORKER_DELAY);
+ await Utils.sleep(this.workerStartDelay);
}
this.getLastWorker().postMessage({ id: WorkerEvents.START_WORKER_ELEMENT, workerData: elementData });
this.getLastWorkerSetElement().numberOfWorkerElements++;
public async start(): Promise<void> {
this.startWorker();
// Start worker sequentially to optimize memory at startup
- await Utils.sleep(Constants.START_WORKER_DELAY);
+ await Utils.sleep(this.workerStartDelay);
}
/**
import { FixedThreadPool, PoolOptions } from 'poolifier';
-import Constants from '../utils/Constants';
import Utils from '../utils/Utils';
import { Worker } from 'worker_threads';
import WorkerAbstract from './WorkerAbstract';
*
* @param {string} workerScript
* @param {number} numberOfThreads
+ * @param {number} startWorkerDelay
*/
- constructor(workerScript: string, numberOfThreads: number) {
- super(workerScript);
+ constructor(workerScript: string, numberOfThreads: number, startWorkerDelay?: number) {
+ super(workerScript, startWorkerDelay);
this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript);
}
public async addElement(elementData: T): Promise<void> {
await this.pool.execute(elementData);
// Start worker sequentially to optimize memory at startup
- await Utils.sleep(Constants.START_WORKER_DELAY);
+ await Utils.sleep(this.workerStartDelay);
}
}