From: Jérôme Benoit Date: Fri, 9 Jun 2023 11:22:46 +0000 (+0200) Subject: fix: rely on worker active ELU in least elu strategy X-Git-Tag: v2.6.0~7^2~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=dd38581f5c4724c7fc431bcfd42106bbc8c8dd17;p=poolifier.git fix: rely on worker active ELU in least elu strategy Signed-off-by: Jérôme Benoit --- 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 5cc02bff..9f6ddbf3 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -62,7 +62,7 @@ export class LeastEluWorkerChoiceStrategy< let leastEluWorkerNodeKey!: number for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerUsage = workerNode.workerUsage - const workerElu = workerUsage.elu?.utilization ?? 0 + const workerElu = workerUsage.elu?.active ?? 0 if (workerElu === 0) { return workerNodeKey } else if (workerElu < minWorkerElu) { diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index 9e69c330..dbe286b4 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -6,7 +6,6 @@ const { FixedClusterPool } = require('../../../lib') const { CircularArray } = require('../../../lib/circular-array') -const TestUtils = require('../../test-utils') describe('Selection strategies test suite', () => { const min = 0 @@ -649,11 +648,12 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU } ) // TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose` + const promises = new Set() const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() - if (i !== max * maxMultiplier - 1) await TestUtils.sleep(500) + promises.add(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { const expectedWorkerUsage = { tasks: { @@ -707,11 +707,12 @@ describe('Selection strategies test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU } ) // TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose` + const promises = new Set() const maxMultiplier = 2 for (let i = 0; i < max * maxMultiplier; i++) { - await pool.execute() - if (i !== max * maxMultiplier - 1) await TestUtils.sleep(500) + promises.add(pool.execute()) } + await Promise.all(promises) for (const workerNode of pool.workerNodes) { const expectedWorkerUsage = { tasks: {