import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- RequiredStatistics,
+ TaskStatistics,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
/** @inheritDoc */
- public readonly requiredStatistics: RequiredStatistics = {
+ public readonly taskStatistics: TaskStatistics = {
runTime: true,
avgRunTime: false,
medRunTime: false,
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
- this.setRequiredStatistics(this.opts)
+ this.setTaskStatistics(this.opts)
}
/** @inheritDoc */
/** @inheritDoc */
public choose (): number {
- const freeWorkerNodeKey = this.findFreeWorkerNodeKey()
- if (freeWorkerNodeKey !== -1) {
- return freeWorkerNodeKey
- }
let minRunTime = Infinity
let leastBusyWorkerNodeKey!: number
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
- const workerRunTime = workerNode.tasksUsage.runTime
+ const workerRunTime = workerNode.workerUsage.runTime.aggregation
if (workerRunTime === 0) {
return workerNodeKey
} else if (workerRunTime < minRunTime) {