- // Start worker sequentially to optimize memory at startup
- await Utils.sleep(Constants.START_WORKER_DELAY);
- }
-}
-
-class DynamicPool extends DynamicThreadPool<WorkerData> {
- private static instance: DynamicPool;
-
- private constructor(min: number, max: number, filename: string, opts?: DynamicThreadPoolOptions) {
- super(min, max, filename, opts);
- }
-
- public static getInstance(min: number, max: number, filename: string): DynamicPool {
- if (!DynamicPool.instance) {
- DynamicPool.instance = new DynamicPool(min, max, filename,
- {
- exitHandler: (code) => {
- if (code !== 0) {
- console.error(`Worker stopped with exit code ${code}`);
- }
- }
- }
- );
- }
- return DynamicPool.instance;
+ // Start element sequentially to optimize memory at startup
+ this.workerOptions.elementStartDelay > 0 &&
+ (await Utils.sleep(this.workerOptions.elementStartDelay));