X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fselection-strategies%2Ffair-share-worker-choice-strategy.ts;h=48f213ffebb1a4577debff4e701ef45f53e2ebed;hb=d354916afe83118073287bcd405dcdf6f4cd9b20;hp=3735f9722319c34656d3498389962859ffd2f060;hpb=6ffb8e34e2276cc0e0f5576749e190d1d914b7d4;p=poolifier.git diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index 3735f972..48f213ff 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -44,10 +44,10 @@ export class FairShareWorkerChoiceStrategy< /** @inheritDoc */ public choose (): Worker { - this.computeWorkerLastVirtualTaskTimestamp() let minWorkerVirtualTaskEndTimestamp = Infinity let chosenWorker!: Worker for (const worker of this.pool.workers) { + this.computeWorkerLastVirtualTaskTimestamp(worker) const workerLastVirtualTaskEndTimestamp = this.workerLastVirtualTaskTimestamp.get(worker)?.end ?? 0 if ( @@ -61,21 +61,21 @@ export class FairShareWorkerChoiceStrategy< } /** - * Computes workers last virtual task timestamp. + * Computes worker last virtual task timestamp. + * + * @param worker The worker. */ - private computeWorkerLastVirtualTaskTimestamp () { - for (const worker of this.pool.workers) { - const workerVirtualTaskStartTimestamp = Math.max( - Date.now(), - this.workerLastVirtualTaskTimestamp.get(worker)?.end ?? -Infinity - ) - const workerVirtualTaskEndTimestamp = - workerVirtualTaskStartTimestamp + - (this.pool.getWorkerAverageTasksRunTime(worker) ?? 0) - this.workerLastVirtualTaskTimestamp.set(worker, { - start: workerVirtualTaskStartTimestamp, - end: workerVirtualTaskEndTimestamp - }) - } + private computeWorkerLastVirtualTaskTimestamp (worker: Worker): void { + const workerVirtualTaskStartTimestamp = Math.max( + Date.now(), + this.workerLastVirtualTaskTimestamp.get(worker)?.end ?? -Infinity + ) + const workerVirtualTaskEndTimestamp = + workerVirtualTaskStartTimestamp + + (this.pool.getWorkerAverageTasksRunTime(worker) ?? 0) + this.workerLastVirtualTaskTimestamp.set(worker, { + start: workerVirtualTaskStartTimestamp, + end: workerVirtualTaskEndTimestamp + }) } }