perf: speed up dynamic worker termination
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Jul 2023 12:15:24 +0000 (14:15 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Jul 2023 12:15:24 +0000 (14:15 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
CHANGELOG.md
src/pools/abstract-pool.ts

index 91530cd66fd3c9ed486a8ed6d2293c3a31bcead7..4bdbedb70db4829af4d162123bb405f02d29c9ab 100644 (file)
@@ -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
 
index 086d7ee82550bc40c46781b83616c1639b32155b..09871491cb7a1ee5d6e7b4ded48696accb2e26e3 100644 (file)
@@ -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<void>)
+        const destroyWorkerNodeBounded = this.destroyWorkerNode.bind(this)
+        if (isAsyncFunction(destroyWorkerNodeBounded)) {
+          (
+            destroyWorkerNodeBounded as (workerNodeKey: number) => Promise<void>
+          )(localWorkerNodeKey).catch(EMPTY_FUNCTION)
+        } else {
+          (destroyWorkerNodeBounded as (workerNodeKey: number) => void)(
+            localWorkerNodeKey
+          )
+        }
       }
     })
     const workerInfo = this.getWorkerInfo(workerNodeKey)