X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fleast-busy-worker-choice-strategy.ts;h=14aee44f97a090f5270fa23d41389e32f0c5ee8d;hb=f59e102739e13698f278f1d9d58ab26ed8150442;hp=aafc07dd6f8ac8f8faa47742bdda2e096449fd55;hpb=5ea80606520ed06f815f4f7485ec9057ac23b176;p=poolifier.git diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index aafc07dd..14aee44f 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -1,4 +1,7 @@ -import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils' +import { + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, + DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS +} from '../../utils' import type { IPool } from '../pool' import type { IWorker } from '../worker' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy' @@ -12,8 +15,8 @@ import type { * Selects the least busy 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 execution response. This can only be serializable data. + * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. + * @typeParam Response - Type of execution response. This can only be structured-cloneable data. */ export class LeastBusyWorkerChoiceStrategy< Worker extends IWorker, @@ -34,11 +37,7 @@ export class LeastBusyWorkerChoiceStrategy< average: false, median: false }, - elu: { - aggregate: false, - average: false, - median: false - } + elu: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } /** @inheritDoc */ @@ -57,11 +56,15 @@ export class LeastBusyWorkerChoiceStrategy< /** @inheritDoc */ public update (): boolean { + return true + } + + /** @inheritDoc */ + public choose (): number { let minTime = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTime = - workerNode.workerUsage.runTime.aggregate + - workerNode.workerUsage.waitTime.aggregate + workerNode.usage.runTime.aggregate + workerNode.usage.waitTime.aggregate if (workerTime === 0) { this.nextWorkerNodeId = workerNodeKey break @@ -70,11 +73,6 @@ export class LeastBusyWorkerChoiceStrategy< this.nextWorkerNodeId = workerNodeKey } } - return true - } - - /** @inheritDoc */ - public choose (): number { return this.nextWorkerNodeId }