X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Fabstract-worker-choice-strategy.ts;h=68e09238b204c35e4f6bb87392021f314e3e2923;hb=daa30e0e21087d1a3cf24b3dd38f703b1aba6d46;hp=4ed7dcae2b0dea882d1eb15a1cb0f88310435e7f;hpb=b1aae69557f4f5c524f665e92882b76f23a19866;p=poolifier.git diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index 4ed7dcae..68e09238 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -30,10 +30,15 @@ export abstract class AbstractWorkerChoiceStrategy< */ protected nextWorkerNodeKey: number | undefined = 0 + /** + * The previous worker node key. + */ + protected previousWorkerNodeKey: number = 0 + /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = { dynamicWorkerUsage: false, - dynamicWorkerReady: false + dynamicWorkerReady: true } /** @inheritDoc */ @@ -88,6 +93,11 @@ export abstract class AbstractWorkerChoiceStrategy< } } + protected resetWorkerNodeKeyProperties (): void { + this.nextWorkerNodeKey = 0 + this.previousWorkerNodeKey = 0 + } + /** @inheritDoc */ public abstract reset (): boolean @@ -113,7 +123,7 @@ export abstract class AbstractWorkerChoiceStrategy< * @returns Whether the worker node is ready or not. */ private isWorkerNodeReady (workerNodeKey: number): boolean { - return this.pool.workerNodes[workerNodeKey].info.ready + return this.pool.workerNodes[workerNodeKey]?.info.ready } /** @@ -143,59 +153,62 @@ export abstract class AbstractWorkerChoiceStrategy< } /** - * Gets the worker task runtime. + * Gets the worker node task runtime. * If the task statistics require the average runtime, the average runtime is returned. * If the task statistics require the median runtime , the median runtime is returned. * * @param workerNodeKey - The worker node key. - * @returns The worker task runtime. + * @returns The worker node task runtime. */ - protected getWorkerTaskRunTime (workerNodeKey: number): number { + protected getWorkerNodeTaskRunTime (workerNodeKey: number): number { return this.taskStatisticsRequirements.runTime.median - ? this.pool.workerNodes[workerNodeKey].usage.runTime?.median ?? 0 - : this.pool.workerNodes[workerNodeKey].usage.runTime?.average ?? 0 + ? this.pool.workerNodes[workerNodeKey].usage.runTime.median ?? 0 + : this.pool.workerNodes[workerNodeKey].usage.runTime.average ?? 0 } /** - * Gets the worker task wait time. + * Gets the worker node task wait time. * If the task statistics require the average wait time, the average wait time is returned. * If the task statistics require the median wait time, the median wait time is returned. * * @param workerNodeKey - The worker node key. - * @returns The worker task wait time. + * @returns The worker node task wait time. */ - protected getWorkerTaskWaitTime (workerNodeKey: number): number { + protected getWorkerNodeTaskWaitTime (workerNodeKey: number): number { return this.taskStatisticsRequirements.waitTime.median - ? this.pool.workerNodes[workerNodeKey].usage.waitTime?.median ?? 0 - : this.pool.workerNodes[workerNodeKey].usage.waitTime?.average ?? 0 + ? this.pool.workerNodes[workerNodeKey].usage.waitTime.median ?? 0 + : this.pool.workerNodes[workerNodeKey].usage.waitTime.average ?? 0 } /** - * Gets the worker task ELU. + * Gets the worker node task ELU. * If the task statistics require the average ELU, the average ELU is returned. * If the task statistics require the median ELU, the median ELU is returned. * * @param workerNodeKey - The worker node key. - * @returns The worker task ELU. + * @returns The worker node task ELU. */ - protected getWorkerTaskElu (workerNodeKey: number): number { + protected getWorkerNodeTaskElu (workerNodeKey: number): number { return this.taskStatisticsRequirements.elu.median - ? this.pool.workerNodes[workerNodeKey].usage.elu.active?.median ?? 0 - : this.pool.workerNodes[workerNodeKey].usage.elu.active?.average ?? 0 + ? this.pool.workerNodes[workerNodeKey].usage.elu.active.median ?? 0 + : this.pool.workerNodes[workerNodeKey].usage.elu.active.average ?? 0 } /** - * Assign to nextWorkerNodeKey property the chosen worker node key. + * Sets safely the previous worker node key. * - * @param chosenWorkerNodeKey - The chosen worker node key. + * @param workerNodeKey - The worker node key. */ - protected assignChosenWorkerNodeKey ( - chosenWorkerNodeKey: number | undefined - ): void { - if (chosenWorkerNodeKey != null) { - this.nextWorkerNodeKey = chosenWorkerNodeKey - } else { - this.nextWorkerNodeKey = undefined + protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void { + this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey + } + + /** + * Check the next worker node eligibility. + */ + protected checkNextWorkerNodeEligibility (): void { + if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { + delete this.nextWorkerNodeKey } }