refactor: cleanup task usage properties namespace
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Jun 2023 11:43:24 +0000 (13:43 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 5 Jun 2023 11:43:24 +0000 (13:43 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
src/pools/worker.ts
tests/pools/abstract/abstract-pool.test.js
tests/pools/cluster/fixed.test.js
tests/pools/selection-strategies/selection-strategies.test.js
tests/pools/thread/fixed.test.js

index 43abfda76c5ed9d07e3ae98fdecb6e40b5f9b025..5088f3d90957bd276756c120d2496e8ffe01bb5a 100644 (file)
@@ -289,7 +289,7 @@ export abstract class AbstractPool<
     this.opts.workerChoiceStrategy = workerChoiceStrategy
     for (const workerNode of this.workerNodes) {
       this.setWorkerNodeTasksUsage(workerNode, {
-        run: 0,
+        ran: 0,
         running: 0,
         runTime: 0,
         runTimeHistory: new CircularArray(),
@@ -468,7 +468,7 @@ export abstract class AbstractPool<
     const workerTasksUsage =
       this.workerNodes[this.getWorkerNodeKey(worker)].tasksUsage
     --workerTasksUsage.running
-    ++workerTasksUsage.run
+    ++workerTasksUsage.ran
     if (message.error != null) {
       ++workerTasksUsage.error
     }
@@ -484,10 +484,10 @@ export abstract class AbstractPool<
       workerTasksUsage.runTime += message.runTime ?? 0
       if (
         this.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime &&
-        workerTasksUsage.run !== 0
+        workerTasksUsage.ran !== 0
       ) {
         workerTasksUsage.avgRunTime =
-          workerTasksUsage.runTime / workerTasksUsage.run
+          workerTasksUsage.runTime / workerTasksUsage.ran
       }
       if (
         this.workerChoiceStrategyContext.getRequiredStatistics().medRunTime &&
@@ -507,10 +507,10 @@ export abstract class AbstractPool<
       workerTasksUsage.waitTime += message.waitTime ?? 0
       if (
         this.workerChoiceStrategyContext.getRequiredStatistics().avgWaitTime &&
-        workerTasksUsage.run !== 0
+        workerTasksUsage.ran !== 0
       ) {
         workerTasksUsage.avgWaitTime =
-          workerTasksUsage.waitTime / workerTasksUsage.run
+          workerTasksUsage.waitTime / workerTasksUsage.ran
       }
       if (
         this.workerChoiceStrategyContext.getRequiredStatistics().medWaitTime &&
@@ -694,7 +694,7 @@ export abstract class AbstractPool<
     return this.workerNodes.push({
       worker,
       tasksUsage: {
-        run: 0,
+        ran: 0,
         running: 0,
         runTime: 0,
         runTimeHistory: new CircularArray(),
index 85e145a041b7868bc96565091a0beec16b7b6d89..86a1ef23f1871ca85c0376db73b3517666e977ba 100644 (file)
@@ -50,7 +50,7 @@ export class LeastUsedWorkerChoiceStrategy<
     let leastUsedWorkerNodeKey!: number
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const tasksUsage = workerNode.tasksUsage
-      const workerTasks = tasksUsage.run + tasksUsage.running
+      const workerTasks = tasksUsage.ran + tasksUsage.running
       if (workerTasks === 0) {
         return workerNodeKey
       } else if (workerTasks < minNumberOfTasks) {
index 35d2c0abaa331ecad6e9a0404deaa90c00ef7d4c..ec75c819cfe9be8a5e56dac0e0c2bdad4cfe7d66 100644 (file)
@@ -64,7 +64,7 @@ export interface TasksUsage {
   /**
    * Number of tasks executed.
    */
-  run: number
+  ran: number
   /**
    * Number of tasks running.
    */
index 80f43dda845c5e4e06b5cc0448b8ef4031f3dad7..03a4ab7e7061ee20c30bc4f0af1d1beb67954fe7 100644 (file)
@@ -336,7 +336,7 @@ describe('Abstract pool test suite', () => {
     )
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: 0,
+        ran: 0,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -377,7 +377,7 @@ describe('Abstract pool test suite', () => {
     }
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: 0,
+        ran: 0,
         running: maxMultiplier,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -393,7 +393,7 @@ describe('Abstract pool test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -423,7 +423,7 @@ describe('Abstract pool test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: expect.any(Number),
+        ran: expect.any(Number),
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -435,13 +435,13 @@ describe('Abstract pool test suite', () => {
         medWaitTime: 0,
         error: 0
       })
-      expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(maxMultiplier)
     }
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: 0,
+        ran: 0,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
index 9fc2b1b456a4cc5e323a14a276f3633372dba596..4980f750cd02bab8146921ffa3dd844ef71ad685 100644 (file)
@@ -99,7 +99,7 @@ describe('Fixed cluster pool test suite', () => {
       expect(workerNode.tasksUsage.running).toBeLessThanOrEqual(
         queuePool.opts.tasksQueueOptions.concurrency
       )
-      expect(workerNode.tasksUsage.run).toBe(0)
+      expect(workerNode.tasksUsage.ran).toBe(0)
       expect(workerNode.tasksQueue.size).toBeGreaterThan(0)
     }
     expect(queuePool.info.runningTasks).toBe(numberOfWorkers)
@@ -112,8 +112,8 @@ describe('Fixed cluster pool test suite', () => {
     await Promise.all(promises)
     for (const workerNode of queuePool.workerNodes) {
       expect(workerNode.tasksUsage.running).toBe(0)
-      expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(maxMultiplier)
       expect(workerNode.tasksQueue.size).toBe(0)
     }
   })
index ec7d10a71132d25e73f248a8020c8956ef9cad03..da261e89f930b94e52b872cff3c1c2b4796d8f26 100644 (file)
@@ -167,7 +167,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -205,7 +205,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -346,7 +346,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -379,7 +379,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -449,7 +449,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: expect.any(Number),
+        ran: expect.any(Number),
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -461,8 +461,8 @@ describe('Selection strategies test suite', () => {
         medWaitTime: 0,
         error: 0
       })
-      expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier)
       expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
     }
     // We need to clean up the resources after our test
@@ -485,7 +485,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: expect.any(Number),
+        ran: expect.any(Number),
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -497,8 +497,8 @@ describe('Selection strategies test suite', () => {
         medWaitTime: 0,
         error: 0
       })
-      expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier)
       expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
     }
     // We need to clean up the resources after our test
@@ -558,7 +558,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -598,7 +598,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -643,7 +643,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -794,7 +794,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: expect.any(Number),
+        ran: expect.any(Number),
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -806,8 +806,8 @@ describe('Selection strategies test suite', () => {
         medWaitTime: 0,
         error: 0
       })
-      expect(workerNode.tasksUsage.run).toBeGreaterThanOrEqual(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThanOrEqual(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier)
       expect(workerNode.tasksUsage.runTime).toBeGreaterThanOrEqual(0)
       expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0)
     }
@@ -841,7 +841,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: expect.any(Number),
+        ran: expect.any(Number),
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -853,8 +853,8 @@ describe('Selection strategies test suite', () => {
         medWaitTime: 0,
         error: 0
       })
-      expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier)
       expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
       expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThan(0)
     }
@@ -893,7 +893,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: expect.any(Number),
+        ran: expect.any(Number),
         running: 0,
         runTime: expect.any(Number),
         runTimeHistory: expect.any(CircularArray),
@@ -905,8 +905,8 @@ describe('Selection strategies test suite', () => {
         medWaitTime: 0,
         error: 0
       })
-      expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(max * maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(max * maxMultiplier)
       expect(workerNode.tasksUsage.runTime).toBeGreaterThan(0)
       expect(workerNode.tasksUsage.medRunTime).toBeGreaterThan(0)
     }
@@ -1059,7 +1059,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
@@ -1119,7 +1119,7 @@ describe('Selection strategies test suite', () => {
     await Promise.all(promises)
     for (const workerNode of pool.workerNodes) {
       expect(workerNode.tasksUsage).toStrictEqual({
-        run: maxMultiplier,
+        ran: maxMultiplier,
         running: 0,
         runTime: 0,
         runTimeHistory: expect.any(CircularArray),
index dcb7fac7f11804289e4a01729ee16980292d9696..c882428083eb77e6f4f72aab5dc6f2aba8446937 100644 (file)
@@ -99,7 +99,7 @@ describe('Fixed thread pool test suite', () => {
       expect(workerNode.tasksUsage.running).toBeLessThanOrEqual(
         queuePool.opts.tasksQueueOptions.concurrency
       )
-      expect(workerNode.tasksUsage.run).toBe(0)
+      expect(workerNode.tasksUsage.ran).toBe(0)
       expect(workerNode.tasksQueue.size).toBeGreaterThan(0)
     }
     expect(queuePool.info.runningTasks).toBe(numberOfThreads)
@@ -112,8 +112,8 @@ describe('Fixed thread pool test suite', () => {
     await Promise.all(promises)
     for (const workerNode of queuePool.workerNodes) {
       expect(workerNode.tasksUsage.running).toBe(0)
-      expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
-      expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier)
+      expect(workerNode.tasksUsage.ran).toBeGreaterThan(0)
+      expect(workerNode.tasksUsage.ran).toBeLessThanOrEqual(maxMultiplier)
       expect(workerNode.tasksQueue.size).toBe(0)
     }
   })