test: add tests for LEAST_ELU worker choice strategy
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 8 Jun 2023 18:12:50 +0000 (20:12 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 8 Jun 2023 18:12:50 +0000 (20:12 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
README.md
src/pools/selection-strategies/least-elu-worker-choice-strategy.ts
tests/pools/selection-strategies/selection-strategies.test.js

index 4c7b33a9368048b9f6cc9853affaa687e8e808c0..33c188722210fe375449ba50b39eaa8300da5322 100644 (file)
--- a/README.md
+++ b/README.md
@@ -163,6 +163,7 @@ An object with these properties:
   - `WorkerChoiceStrategies.ROUND_ROBIN`: Submit tasks to worker in a round robin fashion
   - `WorkerChoiceStrategies.LEAST_USED`: Submit tasks to the worker with the minimum number of running and ran tasks
   - `WorkerChoiceStrategies.LEAST_BUSY`: Submit tasks to the worker with the minimum tasks total execution time
+  - `WorkerChoiceStrategies.LEAST_ELU`: Submit tasks to the worker with the minimum event loop utilization (ELU) (experimental)
   - `WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN`: Submit tasks to worker by using a weighted round robin scheduling algorithm based on tasks execution time
   - `WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN`: Submit tasks to worker by using an interleaved weighted round robin scheduling algorithm based on tasks execution time (experimental)
   - `WorkerChoiceStrategies.FAIR_SHARE`: Submit tasks to worker by using a fair share tasks scheduling algorithm based on tasks execution time
index 41ebf7fb4c5a47d241410aa28cf52d9c4ae44d23..6b3d10b37da19b31b04258a3452482d7d0a7b258 100644 (file)
@@ -25,7 +25,7 @@ export class LeastEluWorkerChoiceStrategy<
   /** @inheritDoc */
   public readonly taskStatistics: TaskStatistics = {
     runTime: false,
-    avgRunTime: true,
+    avgRunTime: false,
     medRunTime: false,
     waitTime: false,
     avgWaitTime: false,
index 24a35810bb3d3327b07cf48b38317dfba9b51a20..a2e43f8a5532dc4aafad0aceef489117940b47f4 100644 (file)
@@ -14,8 +14,8 @@ describe('Selection strategies test suite', () => {
   it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
     expect(WorkerChoiceStrategies.ROUND_ROBIN).toBe('ROUND_ROBIN')
     expect(WorkerChoiceStrategies.LEAST_USED).toBe('LEAST_USED')
-    expect(WorkerChoiceStrategies.LEAST_ELU).toBe('LEAST_ELU')
     expect(WorkerChoiceStrategies.LEAST_BUSY).toBe('LEAST_BUSY')
+    expect(WorkerChoiceStrategies.LEAST_ELU).toBe('LEAST_ELU')
     expect(WorkerChoiceStrategies.FAIR_SHARE).toBe('FAIR_SHARE')
     expect(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN).toBe(
       'WEIGHTED_ROUND_ROBIN'
@@ -555,6 +555,42 @@ describe('Selection strategies test suite', () => {
     await pool.destroy()
   })
 
+  it('Verify LEAST_ELU strategy default tasks usage statistics requirements', async () => {
+    const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU
+    let pool = new FixedThreadPool(
+      max,
+      './tests/worker-files/thread/testWorker.js',
+      { workerChoiceStrategy }
+    )
+    expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+      runTime: false,
+      avgRunTime: false,
+      medRunTime: false,
+      waitTime: false,
+      avgWaitTime: false,
+      medWaitTime: false,
+      elu: true
+    })
+    await pool.destroy()
+    pool = new DynamicThreadPool(
+      min,
+      max,
+      './tests/worker-files/thread/testWorker.js',
+      { workerChoiceStrategy }
+    )
+    expect(pool.workerChoiceStrategyContext.getTaskStatistics()).toStrictEqual({
+      runTime: false,
+      avgRunTime: false,
+      medRunTime: false,
+      waitTime: false,
+      avgWaitTime: false,
+      medWaitTime: false,
+      elu: true
+    })
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
   it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
     const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
     let pool = new FixedThreadPool(