From: Jérôme Benoit Date: Tue, 4 Apr 2023 12:36:34 +0000 (+0200) Subject: perf: allow finer grained control over tasks usage computation X-Git-Tag: v2.4.0~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c6bd2650c2690bd84951a2278820adde1b05b41b;p=poolifier.git perf: allow finer grained control over tasks usage computation Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 81f71634..38457a2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `LESS_BUSY` worker choice strategy. + +### Changed + +- Optimize worker storage in pool. +- Optimize worker alive status check. +- BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`. +- Optimize `LESS_USED` worker choice strategy. +- Update benchmarks versus external threads pools. +- Optimize tasks usage statistics requirements for worker choice strategy. + +### Fixed + +- Ensure trimmable characters are checked at pool initialization. +- Fix message id integer overflow. +- Fix pool worker removal in worker choice strategy internals. +- Fix package publication with pnpm. + ## [2.4.0-3] - 2023-04-04 ### Added diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 66b1ea1d..1ce8c25e 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -261,7 +261,10 @@ export abstract class AbstractPool< } if (this.workerChoiceStrategyContext.getRequiredStatistics().runTime) { workerTasksUsage.runTime += message.taskRunTime ?? 0 - if (workerTasksUsage.run !== 0) { + if ( + this.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime && + workerTasksUsage.run !== 0 + ) { workerTasksUsage.avgRunTime = workerTasksUsage.runTime / workerTasksUsage.run } diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index b1812733..5c2a553d 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -22,7 +22,8 @@ export abstract class AbstractWorkerChoiceStrategy< public readonly isDynamicPool: boolean /** {@inheritDoc} */ public requiredStatistics: RequiredStatistics = { - runTime: false + runTime: false, + avgRunTime: false } /** diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index 57aafe37..7ef28748 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -30,7 +30,8 @@ export class FairShareWorkerChoiceStrategy< implements IWorkerChoiceStrategy { /** {@inheritDoc} */ public readonly requiredStatistics: RequiredStatistics = { - runTime: true + runTime: true, + avgRunTime: true } /** diff --git a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts index 75109a2b..87ee1ef8 100644 --- a/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/less-busy-worker-choice-strategy.ts @@ -21,7 +21,8 @@ export class LessBusyWorkerChoiceStrategy< implements IWorkerChoiceStrategy { /** {@inheritDoc} */ public readonly requiredStatistics: RequiredStatistics = { - runTime: true + runTime: true, + avgRunTime: false } /** {@inheritDoc} */ diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index c0987685..fb864c5b 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -34,6 +34,7 @@ export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies */ export interface RequiredStatistics { runTime: boolean + avgRunTime: boolean } /** diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index ad42ee90..3709cce4 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -32,7 +32,8 @@ export class WeightedRoundRobinWorkerChoiceStrategy< implements IWorkerChoiceStrategy { /** {@inheritDoc} */ public readonly requiredStatistics: RequiredStatistics = { - runTime: true + runTime: true, + avgRunTime: true } /** diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index abfbdb9a..7187a900 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -72,6 +72,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(false) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(false) await pool.destroy() pool = new DynamicThreadPool( min, @@ -82,6 +85,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(false) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(false) // We need to clean up the resources after our test await pool.destroy() }) @@ -213,6 +219,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(false) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(false) await pool.destroy() pool = new DynamicThreadPool( min, @@ -223,6 +232,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(false) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(false) // We need to clean up the resources after our test await pool.destroy() }) @@ -295,6 +307,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(true) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(false) await pool.destroy() pool = new DynamicThreadPool( min, @@ -305,6 +320,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(true) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(false) // We need to clean up the resources after our test await pool.destroy() }) @@ -389,6 +407,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(true) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(true) await pool.destroy() pool = new DynamicThreadPool( min, @@ -399,6 +420,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(true) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(true) // We need to clean up the resources after our test await pool.destroy() }) @@ -549,6 +573,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(true) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(true) await pool.destroy() pool = new DynamicThreadPool( min, @@ -559,6 +586,9 @@ describe('Selection strategies test suite', () => { expect( pool.workerChoiceStrategyContext.getRequiredStatistics().runTime ).toBe(true) + expect( + pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime + ).toBe(true) // We need to clean up the resources after our test await pool.destroy() })