- Optimize worker storage in pool.
- Optimize worker alive status check.
-- Optimize `LESS_RECENTLY_USED` worker choice strategy.
+- Rename worker choice strategy `LESS_RECENTLY_USED to `LESS_USED` .
+- Optimize `LESS_USED` worker choice strategy.
### Fixed
- `workerChoiceStrategy` (optional) - The worker choice strategy to use in this pool:
- `WorkerChoiceStrategies.ROUND_ROBIN`: Submit tasks to worker in a round robbin fashion
- - `WorkerChoiceStrategies.LESS_RECENTLY_USED`: Submit tasks to the less recently used worker
+ - `WorkerChoiceStrategies.LESS_USED`: Submit tasks to the less used worker
- `WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN` Submit tasks to worker using a weighted round robin scheduling algorithm based on tasks execution time
- `WorkerChoiceStrategies.FAIR_SHARE`: Submit tasks to worker using a fair share tasks scheduling algorithm based on tasks execution time
size / 2,
size * 3,
'./benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
const dynamicPoolWeightedRoundRobin = new DynamicClusterPool(
const fixedPoolLessRecentlyUsed = new FixedClusterPool(
size,
'./benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
const fixedPoolWeightedRoundRobin = new FixedClusterPool(
size / 2,
size * 3,
'./benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
const dynamicPoolWeightedRoundRobin = new DynamicThreadPool(
const fixedPoolLessRecentlyUsed = new FixedThreadPool(
size,
'./benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
const fixedPoolWeightedRoundRobin = new FixedThreadPool(
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
/**
- * Selects the less recently used worker.
+ * Selects the less used worker.
*
* @typeParam Worker - Type of worker which manages the strategy.
* @typeParam Data - Type of data sent to the worker. This can only be serializable data.
* @typeParam Response - Type of response of execution. This can only be serializable data.
*/
-export class LessRecentlyUsedWorkerChoiceStrategy<
+export class LessUsedWorkerChoiceStrategy<
Worker extends IPoolWorker,
Data,
Response
*/
ROUND_ROBIN: 'ROUND_ROBIN',
/**
- * Less recently used worker selection strategy.
+ * Less used worker selection strategy.
*/
- LESS_RECENTLY_USED: 'LESS_RECENTLY_USED',
+ LESS_USED: 'LESS_USED',
/**
* Fair share worker selection strategy.
*/
import type { IPoolInternal } from '../pool-internal'
import type { IPoolWorker } from '../pool-worker'
import { FairShareWorkerChoiceStrategy } from './fair-share-worker-choice-strategy'
-import { LessRecentlyUsedWorkerChoiceStrategy } from './less-recently-used-worker-choice-strategy'
+import { LessUsedWorkerChoiceStrategy } from './less-used-worker-choice-strategy'
import { RoundRobinWorkerChoiceStrategy } from './round-robin-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
switch (workerChoiceStrategy) {
case WorkerChoiceStrategies.ROUND_ROBIN:
return new RoundRobinWorkerChoiceStrategy(pool)
- case WorkerChoiceStrategies.LESS_RECENTLY_USED:
- return new LessRecentlyUsedWorkerChoiceStrategy(pool)
+ case WorkerChoiceStrategies.LESS_USED:
+ return new LessUsedWorkerChoiceStrategy(pool)
case WorkerChoiceStrategies.FAIR_SHARE:
return new FairShareWorkerChoiceStrategy(pool)
case WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN:
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js',
{
- workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED,
+ workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED,
enableEvents: false,
messageHandler: testHandler,
errorHandler: testHandler,
expect(pool.opts.enableEvents).toBe(false)
expect(pool.emitter).toBeUndefined()
expect(pool.opts.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_USED
)
expect(pool.opts.messageHandler).toStrictEqual(testHandler)
expect(pool.opts.errorHandler).toStrictEqual(testHandler)
RoundRobinWorkerChoiceStrategy
} = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy')
const {
- LessRecentlyUsedWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/less-recently-used-worker-choice-strategy')
+ LessUsedWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy')
const {
FairShareWorkerChoiceStrategy
} = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy')
expect(strategy).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
})
- it('Verify that getWorkerChoiceStrategy() can return LESS_RECENTLY_USED strategy', () => {
+ it('Verify that getWorkerChoiceStrategy() can return LESS_USED strategy', () => {
const strategy = getWorkerChoiceStrategy(
pool,
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_USED
)
- expect(strategy).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy)
+ expect(strategy).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
})
it('Verify that getWorkerChoiceStrategy() can return FAIR_SHARE strategy', () => {
it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
expect(WorkerChoiceStrategies.ROUND_ROBIN).toBe('ROUND_ROBIN')
- expect(WorkerChoiceStrategies.LESS_RECENTLY_USED).toBe('LESS_RECENTLY_USED')
+ expect(WorkerChoiceStrategies.LESS_USED).toBe('LESS_USED')
expect(WorkerChoiceStrategies.FAIR_SHARE).toBe('FAIR_SHARE')
expect(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN).toBe(
'WEIGHTED_ROUND_ROBIN'
await pool.destroy()
})
- it('Verify LESS_RECENTLY_USED strategy is taken at pool creation', async () => {
+ it('Verify LESS_USED strategy is taken at pool creation', async () => {
const pool = new FixedThreadPool(
max,
'./tests/worker-files/thread/testWorker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
expect(pool.opts.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_USED
)
// We need to clean up the resources after our test
await pool.destroy()
})
- it('Verify LESS_RECENTLY_USED strategy can be set after pool creation', async () => {
+ it('Verify LESS_USED strategy can be set after pool creation', async () => {
const pool = new FixedThreadPool(
max,
'./tests/worker-files/thread/testWorker.js'
)
- pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_RECENTLY_USED)
+ pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
expect(pool.opts.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_USED
)
// We need to clean up the resources after our test
await pool.destroy()
})
- it('Verify LESS_RECENTLY_USED strategy default tasks usage statistics requirements', async () => {
+ it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
let pool = new FixedThreadPool(
max,
'./tests/worker-files/thread/testWorker.js'
)
- pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_RECENTLY_USED)
+ pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
expect(
pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
.requiredStatistics.runTime
max,
'./tests/worker-files/thread/testWorker.js'
)
- pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_RECENTLY_USED)
+ pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
expect(
pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
.requiredStatistics.runTime
await pool.destroy()
})
- it('Verify LESS_RECENTLY_USED strategy can be run in a fixed pool', async () => {
+ it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
const pool = new FixedThreadPool(
max,
'./tests/worker-files/thread/testWorker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
// TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
const promises = []
await pool.destroy()
})
- it('Verify LESS_RECENTLY_USED strategy can be run in a dynamic pool', async () => {
+ it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
const pool = new DynamicThreadPool(
min,
max,
'./tests/worker-files/thread/testWorker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
)
// TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
const promises = []
RoundRobinWorkerChoiceStrategy
} = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy')
const {
- LessRecentlyUsedWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/less-recently-used-worker-choice-strategy')
+ LessUsedWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy')
const {
FairShareWorkerChoiceStrategy
} = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy')
).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
})
- it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and fixed pool', () => {
+ it('Verify that setWorkerChoiceStrategy() works with LESS_USED and fixed pool', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
)
workerChoiceStrategyContext.setWorkerChoiceStrategy(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_USED
)
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy()
- ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy)
+ ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
})
- it('Verify that setWorkerChoiceStrategy() works with LESS_RECENTLY_USED and dynamic pool', () => {
+ it('Verify that setWorkerChoiceStrategy() works with LESS_USED and dynamic pool', () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
dynamicPool
)
workerChoiceStrategyContext.setWorkerChoiceStrategy(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_USED
)
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy()
).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
expect(
workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
- ).toBeInstanceOf(LessRecentlyUsedWorkerChoiceStrategy)
+ ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
})
it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and fixed pool', () => {