'unlink',
'unregister',
'utf8',
- 'workerpool'
+ 'workerpool',
+ 'wwr'
],
skipIfMatch: ['^@.*', '^plugin:.*']
}
### Fixed
- Fix worker function type definition and validation.
+- Fix worker choice strategy options handling.
## [2.4.8] - 2023-04-12
protected readonly pool: IPool<Worker, Data, Response>,
protected readonly opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
- this.checkOptions(this.opts)
this.isDynamicPool = this.pool.type === PoolType.DYNAMIC
this.choose.bind(this)
}
- private checkOptions (opts: WorkerChoiceStrategyOptions): void {
+ protected checkOptions (opts: WorkerChoiceStrategyOptions): void {
if (this.requiredStatistics.avgRunTime && opts.medRunTime === true) {
- this.requiredStatistics.medRunTime = true
+ this.requiredStatistics.avgRunTime = false
+ this.requiredStatistics.medRunTime = opts.medRunTime as boolean
}
}
+import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
+import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- RequiredStatistics
+ RequiredStatistics,
+ WorkerChoiceStrategyOptions
} from './selection-strategies-types'
/**
WorkerVirtualTaskTimestamp
> = new Map<number, WorkerVirtualTaskTimestamp>()
+ /** @inheritDoc */
+ public constructor (
+ pool: IPool<Worker, Data, Response>,
+ opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ ) {
+ super(pool, opts)
+ this.checkOptions(opts)
+ }
+
/** @inheritDoc */
public reset (): boolean {
this.workerLastVirtualTaskTimestamp.clear()
+import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
+import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- RequiredStatistics
+ RequiredStatistics,
+ WorkerChoiceStrategyOptions
} from './selection-strategies-types'
/**
medRunTime: false
}
+ /** @inheritDoc */
+ public constructor (
+ pool: IPool<Worker, Data, Response>,
+ opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ ) {
+ super(pool, opts)
+ this.checkOptions(opts)
+ }
+
/** @inheritDoc */
public reset (): boolean {
return true
+import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
+import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
-import type { IWorkerChoiceStrategy } from './selection-strategies-types'
+import type {
+ IWorkerChoiceStrategy,
+ WorkerChoiceStrategyOptions
+} from './selection-strategies-types'
/**
* Selects the less used worker.
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
+ /** @inheritDoc */
+ public constructor (
+ pool: IPool<Worker, Data, Response>,
+ opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ ) {
+ super(pool, opts)
+ this.checkOptions(opts)
+ }
+
/** @inheritDoc */
public reset (): boolean {
return true
+import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
+import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
-import type { IWorkerChoiceStrategy } from './selection-strategies-types'
+import type {
+ IWorkerChoiceStrategy,
+ WorkerChoiceStrategyOptions
+} from './selection-strategies-types'
/**
* Selects the next worker in a round robin fashion.
*/
private nextWorkerNodeId: number = 0
+ /** @inheritDoc */
+ public constructor (
+ pool: IPool<Worker, Data, Response>,
+ opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ ) {
+ super(pool, opts)
+ this.checkOptions(opts)
+ }
+
/** @inheritDoc */
public reset (): boolean {
this.nextWorkerNodeId = 0
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
import type { IPool } from '../pool'
+import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
/**
* Virtual task runtime.
TaskRunTime
>()
- /**
- * Constructs a worker choice strategy that selects with a weighted round robin scheduling algorithm.
- *
- * @param pool - The pool instance.
- * @param opts - The worker choice strategy options.
- */
+ /** @inheritDoc */
public constructor (
pool: IPool<Worker, Data, Response>,
- opts?: WorkerChoiceStrategyOptions
+ opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
+ this.checkOptions(opts)
this.defaultWorkerWeight = this.computeWorkerWeight()
this.initWorkersTaskRunTime()
}
workerChoiceStrategy
)
})
+
+ it.only('Verify that worker choice strategy options enable median run time pool statistics', () => {
+ const wwrWorkerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ fixedPool,
+ wwrWorkerChoiceStrategy,
+ {
+ medRunTime: true
+ }
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe(
+ false
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe(
+ true
+ )
+ workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ dynamicPool,
+ wwrWorkerChoiceStrategy,
+ {
+ medRunTime: true
+ }
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe(
+ false
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe(
+ true
+ )
+ const fsWorkerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
+ workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ fixedPool,
+ fsWorkerChoiceStrategy,
+ {
+ medRunTime: true
+ }
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe(
+ false
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe(
+ true
+ )
+ workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+ dynamicPool,
+ fsWorkerChoiceStrategy,
+ {
+ medRunTime: true
+ }
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().avgRunTime).toBe(
+ false
+ )
+ expect(workerChoiceStrategyContext.getRequiredStatistics().medRunTime).toBe(
+ true
+ )
+ })
})