* 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,
average: false,
median: false
},
- elu: false
+ elu: {
+ aggregate: false,
+ average: false,
+ median: false
+ }
}
/** @inheritDoc */
/** @inheritDoc */
public choose (): number {
let minTime = Infinity
- let leastBusyWorkerNodeKey!: number
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTime =
workerNode.workerUsage.runTime.aggregate +
workerNode.workerUsage.waitTime.aggregate
if (workerTime === 0) {
- return workerNodeKey
+ this.nextWorkerNodeId = workerNodeKey
+ break
} else if (workerTime < minTime) {
minTime = workerTime
- leastBusyWorkerNodeKey = workerNodeKey
+ this.nextWorkerNodeId = workerNodeKey
}
}
- return leastBusyWorkerNodeKey
+ return this.nextWorkerNodeId
}
/** @inheritDoc */