From: Jérôme Benoit Date: Fri, 21 Jul 2023 12:15:24 +0000 (+0200) Subject: perf: speed up dynamic worker termination X-Git-Tag: v2.6.20~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7c89e6a4cb61feed3743298f9813871af02df875;p=poolifier.git perf: speed up dynamic worker termination Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 91530cd6..4bdbedb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Drastically reduce lookup by worker in the worker nodes. +- Drastically reduce lookups by worker in the worker nodes. ## [2.6.19] - 2023-07-20 diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 086d7ee8..09871491 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -10,6 +10,7 @@ import { DEFAULT_TASK_NAME, DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS, EMPTY_FUNCTION, + isAsyncFunction, isKillBehavior, isPlainObject, median, @@ -913,7 +914,16 @@ export abstract class AbstractPool< this.tasksQueueSize(localWorkerNodeKey) === 0))) ) { // Kill message received from the worker: no new tasks are submitted to that worker for a while ( > maxInactiveTime) - void (this.destroyWorkerNode(localWorkerNodeKey) as Promise) + const destroyWorkerNodeBounded = this.destroyWorkerNode.bind(this) + if (isAsyncFunction(destroyWorkerNodeBounded)) { + ( + destroyWorkerNodeBounded as (workerNodeKey: number) => Promise + )(localWorkerNodeKey).catch(EMPTY_FUNCTION) + } else { + (destroyWorkerNodeBounded as (workerNodeKey: number) => void)( + localWorkerNodeKey + ) + } } }) const workerInfo = this.getWorkerInfo(workerNodeKey)