: this.pool.workerNodes[workerNodeKey].usage.elu.active?.average ?? 0
}
+ /**
+ * Sets safely the previous worker node key.
+ *
+ * @param workerNodeKey - The worker node key.
+ */
+ protected setPreviousWorkerNodeKey (workerNodeKey: number | undefined): void {
+ this.previousWorkerNodeKey = workerNodeKey ?? this.previousWorkerNodeKey
+ }
+
/**
* Check the next worker node eligibility.
*
- * @param chosenNextWorkerNodeKey - The chosen next worker node key.
+ * @param previousWorkerNodeKey - The previous worker node key.
*/
protected checkNextWorkerNodeEligibility (
- chosenNextWorkerNodeKey: number | undefined
+ previousWorkerNodeKey: number | undefined
): void {
if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) {
this.nextWorkerNodeKey = undefined
- this.previousWorkerNodeKey =
- chosenNextWorkerNodeKey ?? this.previousWorkerNodeKey
+ this.setPreviousWorkerNodeKey(previousWorkerNodeKey)
}
}
/** @inheritDoc */
public choose (): number | undefined {
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
this.nextWorkerNodeKey = this.fairShareNextWorkerNodeKey()
return this.nextWorkerNodeKey
}
}
private fairShareNextWorkerNodeKey (): number | undefined {
- let minWorkerVirtualTaskEndTimestamp = Infinity
let chosenWorkerNodeKey: number | undefined
+ let minWorkerVirtualTaskEndTimestamp = Infinity
for (const [workerNodeKey] of this.pool.workerNodes.entries()) {
if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) {
this.computeWorkerVirtualTaskEndTimestamp(workerNodeKey)
this.workerVirtualTaskRunTime =
this.workerVirtualTaskRunTime +
this.getWorkerTaskRunTime(workerNodeKey)
- this.previousWorkerNodeKey =
- this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
this.nextWorkerNodeKey = workerNodeKey
return this.nextWorkerNodeKey
}
/** @inheritDoc */
public choose (): number | undefined {
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
this.nextWorkerNodeKey = this.leastBusyNextWorkerNodeKey()
return this.nextWorkerNodeKey
}
}
private leastBusyNextWorkerNodeKey (): number | undefined {
- let minTime = Infinity
let chosenWorkerNodeKey: number | undefined
+ let minTime = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTime =
(workerNode.usage.runTime?.aggregate ?? 0) +
/** @inheritDoc */
public choose (): number | undefined {
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
this.nextWorkerNodeKey = this.leastEluNextWorkerNodeKey()
return this.nextWorkerNodeKey
}
}
private leastEluNextWorkerNodeKey (): number | undefined {
- let minWorkerElu = Infinity
let chosenWorkerNodeKey: number | undefined
+ let minWorkerElu = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerUsage = workerNode.usage
const workerElu = workerUsage.elu?.active?.aggregate ?? 0
/** @inheritDoc */
public choose (): number | undefined {
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
this.nextWorkerNodeKey = this.leastUsedNextWorkerNodeKey()
return this.nextWorkerNodeKey
}
}
private leastUsedNextWorkerNodeKey (): number | undefined {
- let minNumberOfTasks = Infinity
let chosenWorkerNodeKey: number | undefined
+ let minNumberOfTasks = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTaskStatistics = workerNode.usage.tasks
const workerTasks =
/** @inheritDoc */
public choose (): number | undefined {
const chosenWorkerNodeKey = this.nextWorkerNodeKey
+ this.setPreviousWorkerNodeKey(chosenWorkerNodeKey)
this.roundRobinNextWorkerNodeKey()
return chosenWorkerNodeKey
}
/** @inheritDoc */
public choose (): number | undefined {
- const chosenWorkerNodeKey = this.nextWorkerNodeKey
- this.weightedRoundRobinNextWorkerNodeKey()
- return chosenWorkerNodeKey
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
+ return this.weightedRoundRobinNextWorkerNodeKey()
}
/** @inheritDoc */