From 97dc65d91cefa67e1d1d1f6753ddf6d468a46424 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 30 Apr 2024 20:39:25 +0200 Subject: [PATCH] fix: set pool start timestamp at start() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 6 +++--- src/pools/abstract-pool.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ec5db156..473386a6 100644 --- a/README.md +++ b/README.md @@ -40,15 +40,15 @@ Please consult our [general guidelines](#general-guidelines). - Proper integration with Node.js [async_hooks](https://nodejs.org/api/async_hooks.html) :white_check_mark: - Support for CommonJS, ESM and TypeScript :white_check_mark: - Support for [worker_threads](https://nodejs.org/api/worker_threads.html) and [cluster](https://nodejs.org/api/cluster.html) Node.js modules :white_check_mark: -- Support for multiple task functions with per task function queuing priority and tasks distribution strategy :white_check_mark: -- Support for task functions [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations at runtime :white_check_mark: -- Support for sync and async task functions :white_check_mark: - Tasks distribution strategies :white_check_mark: - Lockless tasks queueing :white_check_mark: - Queued tasks rescheduling: - Task stealing on idle :white_check_mark: - Tasks stealing under back pressure :white_check_mark: - Tasks redistribution on worker error :white_check_mark: +- Support for sync and async task functions :white_check_mark: +- Support for multiple task functions with per task function queuing priority and tasks distribution strategy :white_check_mark: +- Support for task functions [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations at runtime :white_check_mark: - General guidelines on pool choice :white_check_mark: - Error handling out of the box :white_check_mark: - Widely tested :white_check_mark: diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index ba632bb1..e18f1499 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -137,7 +137,7 @@ export abstract class AbstractPool< /** * The start timestamp of the pool. */ - private readonly startTimestamp + private startTimestamp?: number /** * Constructs a new poolifier pool. @@ -193,8 +193,6 @@ export abstract class AbstractPool< if (this.opts.startWorkers === true) { this.start() } - - this.startTimestamp = performance.now() } private checkPoolType (): void { @@ -487,6 +485,9 @@ export abstract class AbstractPool< * @returns The pool utilization. */ private get utilization (): number { + if (this.startTimestamp == null) { + return 0 + } const poolTimeCapacity = (performance.now() - this.startTimestamp) * (this.maximumNumberOfWorkers ?? this.minimumNumberOfWorkers) @@ -1089,6 +1090,7 @@ export abstract class AbstractPool< this.startMinimumNumberOfWorkers() this.starting = false this.started = true + this.startTimestamp = performance.now() } /** @inheritDoc */ @@ -1113,6 +1115,7 @@ export abstract class AbstractPool< this.readyEventEmitted = false this.destroying = false this.started = false + delete this.startTimestamp } private async sendKillMessageToWorker (workerNodeKey: number): Promise { -- 2.34.1