- public choose (): number {
- // const freeWorkerNodeKey = this.findFreeWorkerNodeKey()
- // if (freeWorkerNodeKey !== -1) {
- // return freeWorkerNodeKey
- // }
- let minRunTime = Infinity
- let leastBusyWorkerNodeKey!: number
- for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
- const workerRunTime = workerNode.tasksUsage.runTime
- if (workerRunTime === 0) {
- return workerNodeKey
- } else if (workerRunTime < minRunTime) {
- minRunTime = workerRunTime
- leastBusyWorkerNodeKey = workerNodeKey
- }
- }
- return leastBusyWorkerNodeKey
+ public choose (): number | undefined {
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
+ this.nextWorkerNodeKey = this.leastBusyNextWorkerNodeKey()
+ return this.nextWorkerNodeKey