From 949194eb4b838e9d22dcc4d16649521f7b9e79c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 11 Jul 2023 16:56:02 +0200 Subject: [PATCH] feat: make the remaining worker choice strategies worker readiness aware MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 1 + .../round-robin-worker-choice-strategy.ts | 4 +++- .../weighted-round-robin-worker-choice-strategy.ts | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 063e40d2..a3b46cee 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1135,6 +1135,7 @@ export abstract class AbstractPool< */ private pushWorkerNode (worker: Worker): number { const workerNode = new WorkerNode(worker, this.worker) + // Flag the worker as ready at pool startup. if (this.starting) { workerNode.info.ready = true } diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 222a0349..b023234a 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -50,7 +50,9 @@ export class RoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { const chosenWorkerNodeKey = this.nextWorkerNodeKey - this.roundRobinNextWorkerNodeKey() + do { + this.roundRobinNextWorkerNodeKey() + } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey)) return chosenWorkerNodeKey } diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 4921df6d..fecba414 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -77,7 +77,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy< /** @inheritDoc */ public choose (): number { const chosenWorkerNodeKey = this.nextWorkerNodeKey - this.weightedRoundRobinNextWorkerNodeKey() + do { + this.weightedRoundRobinNextWorkerNodeKey() + } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey)) return chosenWorkerNodeKey } -- 2.34.1