From db703c75cdbc0ec6dffbf701a4b4c4fd659cc8b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 18 Jun 2023 18:02:56 +0200 Subject: [PATCH] refactor: partially revert strategies optimization MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 1 - .../fair-share-worker-choice-strategy.ts | 10 +++++----- .../least-busy-worker-choice-strategy.ts | 10 +++++----- .../least-elu-worker-choice-strategy.ts | 10 +++++----- .../least-used-worker-choice-strategy.ts | 10 +++++----- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40a1eac2..9058bed6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Optimize O(1) queue implementation. -- Optimize worker choice strategies: pre-choose the worker node key by executing the choice algorithm after tasks submission. ## [2.6.2] - 2023-06-12 diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index 39da59a0..7b3ad3f7 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -66,6 +66,11 @@ export class FairShareWorkerChoiceStrategy< /** @inheritDoc */ public update (workerNodeKey: number): boolean { this.computeWorkerVirtualTaskEndTimestamp(workerNodeKey) + return true + } + + /** @inheritDoc */ + public choose (): number { let minWorkerVirtualTaskEndTimestamp = Infinity for (const [workerNodeKey] of this.pool.workerNodes.entries()) { if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) { @@ -78,11 +83,6 @@ export class FairShareWorkerChoiceStrategy< this.nextWorkerNodeId = workerNodeKey } } - return true - } - - /** @inheritDoc */ - public choose (): number { return this.nextWorkerNodeId } diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index aafc07dd..84476eed 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -57,6 +57,11 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public update (): boolean { + return true + } + + /** @inheritDoc */ + public choose (): number { let minTime = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTime = @@ -70,11 +75,6 @@ export class LeastBusyWorkerChoiceStrategy< this.nextWorkerNodeId = workerNodeKey } } - return true - } - - /** @inheritDoc */ - public choose (): number { return this.nextWorkerNodeId } diff --git a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts index 5df742a6..30491dce 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -57,6 +57,11 @@ export class LeastEluWorkerChoiceStrategy< /** @inheritDoc */ public update (): boolean { + return true + } + + /** @inheritDoc */ + public choose (): number { let minWorkerElu = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerUsage = workerNode.workerUsage @@ -69,11 +74,6 @@ export class LeastEluWorkerChoiceStrategy< this.nextWorkerNodeId = workerNodeKey } } - return true - } - - /** @inheritDoc */ - public choose (): number { return this.nextWorkerNodeId } diff --git a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts index 922659d3..aaa6c21d 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -37,6 +37,11 @@ export class LeastUsedWorkerChoiceStrategy< /** @inheritDoc */ public update (): boolean { + return true + } + + /** @inheritDoc */ + public choose (): number { let minNumberOfTasks = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTaskStatistics = workerNode.workerUsage.tasks @@ -52,11 +57,6 @@ export class LeastUsedWorkerChoiceStrategy< this.nextWorkerNodeId = workerNodeKey } } - return true - } - - /** @inheritDoc */ - public choose (): number { return this.nextWorkerNodeId } -- 2.34.1