fix: rely on worker active ELU in least elu strategy
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Jun 2023 11:22:46 +0000 (13:22 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 9 Jun 2023 11:22:46 +0000 (13:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/least-elu-worker-choice-strategy.ts
tests/pools/selection-strategies/selection-strategies.test.js

index 5cc02bffbc58997dc872ad023f13f7308a903640..9f6ddbf3f407658ea32046af66dfe294bb8f45df 100644 (file)
@@ -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) {
index 9e69c330c09272d382da24339f3b323568807063..dbe286b40e5a46f7b262a700f130f4aad1bf82c4 100644 (file)
@@ -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: {