return this.pool.workerNodes[workerNodeKey]?.info?.ready ?? false
}
+ /**
+ * Check the next worker node readiness.
+ */
+ protected checkNextWorkerNodeReadiness (): void {
+ if (!this.isWorkerNodeReady(this.nextWorkerNodeKey as number)) {
+ delete this.nextWorkerNodeKey
+ }
+ }
+
/**
* Gets the worker node task runtime.
* If the task statistics require the average runtime, the average runtime is returned.
}
private interleavedWeightedRoundRobinNextWorkerNodeId (): void {
- do {
- if (
- this.roundId === this.roundWeights.length - 1 &&
- this.workerNodeId === this.pool.workerNodes.length - 1
- ) {
- this.roundId = 0
- this.workerNodeId = 0
- } else if (this.workerNodeId === this.pool.workerNodes.length - 1) {
- this.roundId = this.roundId + 1
- this.workerNodeId = 0
- } else {
- this.workerNodeId = this.workerNodeId + 1
- }
- } while (!this.isWorkerNodeReady(this.workerNodeId))
+ if (
+ this.roundId === this.roundWeights.length - 1 &&
+ this.workerNodeId === this.pool.workerNodes.length - 1
+ ) {
+ this.roundId = 0
+ this.workerNodeId = 0
+ } else if (this.workerNodeId === this.pool.workerNodes.length - 1) {
+ this.roundId = this.roundId + 1
+ this.workerNodeId = 0
+ } else {
+ this.workerNodeId = this.workerNodeId + 1
+ }
}
/** @inheritDoc */
const chosenWorkerNodeKey = this.nextWorkerNodeKey
this.setPreviousWorkerNodeKey(chosenWorkerNodeKey)
this.roundRobinNextWorkerNodeKey()
+ this.checkNextWorkerNodeReadiness()
return chosenWorkerNodeKey
}
}
private roundRobinNextWorkerNodeKey (): number | undefined {
- do {
- this.nextWorkerNodeKey =
- this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
- ? 0
- : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
- } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey))
+ this.nextWorkerNodeKey =
+ this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
+ ? 0
+ : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
return this.nextWorkerNodeKey
}
}
/** @inheritDoc */
public choose (): number | undefined {
this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
- return this.weightedRoundRobinNextWorkerNodeKey()
+ this.weightedRoundRobinNextWorkerNodeKey()
+ this.checkNextWorkerNodeReadiness()
+ return this.nextWorkerNodeKey
}
/** @inheritDoc */
}
private weightedRoundRobinNextWorkerNodeKey (): number | undefined {
- do {
- const workerWeight =
- this.opts.weights?.[
+ const workerWeight =
+ this.opts.weights?.[
+ this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
+ ] ?? this.defaultWorkerWeight
+ if (this.workerNodeVirtualTaskRunTime < workerWeight) {
+ this.workerNodeVirtualTaskRunTime =
+ this.workerNodeVirtualTaskRunTime +
+ this.getWorkerNodeTaskRunTime(
this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
- ] ?? this.defaultWorkerWeight
- if (this.workerNodeVirtualTaskRunTime < workerWeight) {
- this.workerNodeVirtualTaskRunTime =
- this.workerNodeVirtualTaskRunTime +
- this.getWorkerNodeTaskRunTime(
- this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
- )
- } else {
- this.nextWorkerNodeKey =
- this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
- ? 0
- : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
- this.workerNodeVirtualTaskRunTime = 0
- }
- } while (!this.isWorkerNodeReady(this.nextWorkerNodeKey as number))
+ )
+ } else {
+ this.nextWorkerNodeKey =
+ this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
+ ? 0
+ : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
+ this.workerNodeVirtualTaskRunTime = 0
+ }
return this.nextWorkerNodeKey
}
}