From: Jérôme Benoit Date: Mon, 5 Jun 2023 11:43:24 +0000 (+0200) Subject: refactor: cleanup task usage properties namespace X-Git-Tag: v2.5.4~20^2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1ab50fe5ad0b27a13a48047f9414d4138d43a5cd;p=poolifier.git refactor: cleanup task usage properties namespace Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 43abfda7..5088f3d9 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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(), 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 85e145a0..86a1ef23 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -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) { diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 35d2c0ab..ec75c819 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -64,7 +64,7 @@ export interface TasksUsage { /** * Number of tasks executed. */ - run: number + ran: number /** * Number of tasks running. */ diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 80f43dda..03a4ab7e 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -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), diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 9fc2b1b4..4980f750 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -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) } }) diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index ec7d10a7..da261e89 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -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), diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index dcb7fac7..c8824280 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -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) } })