Data = unknown,
Response = unknown
> implements IWorkerChoiceStrategy {
- // /**
- // * Toggles finding the last free worker node key.
- // */
- // private toggleFindLastFreeWorkerNodeKey: boolean = false
-
/**
* The next worker node key.
*/
return this.pool.workerNodes[workerNodeKey].info.ready
}
- // /**
- // * Finds a free worker node key.
- // *
- // * @returns The free worker node key or `-1` if there is no free worker node.
- // */
- // protected findFreeWorkerNodeKey (): number {
- // if (this.toggleFindLastFreeWorkerNodeKey) {
- // this.toggleFindLastFreeWorkerNodeKey = false
- // return this.findLastFreeWorkerNodeKey()
- // }
- // this.toggleFindLastFreeWorkerNodeKey = true
- // return this.findFirstFreeWorkerNodeKey()
- // }
-
/**
* Gets the worker task runtime.
* If the task statistics require the average runtime, the average runtime is returned.
}
return Math.round(cpusCycleTimeWeight / cpus().length)
}
-
- // /**
- // * Finds the first free worker node key based on the number of tasks the worker has applied.
- // *
- // * If a worker is found with `0` executing tasks, it is detected as free and its worker node key is returned.
- // *
- // * If no free worker is found, `-1` is returned.
- // *
- // * @returns A worker node key if there is one, `-1` otherwise.
- // */
- // private findFirstFreeWorkerNodeKey (): number {
- // return this.pool.workerNodes.findIndex(workerNode => {
- // return workerNode.usage.tasks.executing === 0
- // })
- // }
-
- // /**
- // * Finds the last free worker node key based on the number of tasks the worker has applied.
- // *
- // * If a worker is found with `0` executing tasks, it is detected as free and its worker node key is returned.
- // *
- // * If no free worker is found, `-1` is returned.
- // *
- // * @returns A worker node key if there is one, `-1` otherwise.
- // */
- // private findLastFreeWorkerNodeKey (): number {
- // // It requires node >= 18.0.0:
- // // return this.pool.workerNodes.findLastIndex(workerNode => {
- // // return workerNode.usage.tasks.executing === 0
- // // })
- // for (
- // let workerNodeKey = this.pool.workerNodes.length - 1;
- // workerNodeKey >= 0;
- // workerNodeKey--
- // ) {
- // if (this.pool.workerNodes[workerNodeKey].usage.tasks.executing === 0) {
- // return workerNodeKey
- // }
- // }
- // return -1
- // }
}
/** @inheritDoc */
public choose (): number {
- this.fairShareNextWorkerNodeKey()
- return this.nextWorkerNodeKey
+ return this.fairShareNextWorkerNodeKey()
}
/** @inheritDoc */
return true
}
- private fairShareNextWorkerNodeKey (): void {
+ private fairShareNextWorkerNodeKey (): number {
let minWorkerVirtualTaskEndTimestamp = Infinity
for (const [workerNodeKey] of this.pool.workerNodes.entries()) {
if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) {
this.nextWorkerNodeKey = workerNodeKey
}
}
+ return this.nextWorkerNodeKey
}
/**
/** @inheritDoc */
public choose (): number {
- this.leastBusyNextWorkerNodeKey()
- return this.nextWorkerNodeKey
+ return this.leastBusyNextWorkerNodeKey()
}
/** @inheritDoc */
return true
}
- private leastBusyNextWorkerNodeKey (): void {
+ private leastBusyNextWorkerNodeKey (): number {
let minTime = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTime =
this.nextWorkerNodeKey = workerNodeKey
}
}
+ return this.nextWorkerNodeKey
}
}
/** @inheritDoc */
public choose (): number {
- this.leastEluNextWorkerNodeKey()
- return this.nextWorkerNodeKey
+ return this.leastEluNextWorkerNodeKey()
}
/** @inheritDoc */
return true
}
- private leastEluNextWorkerNodeKey (): void {
+ private leastEluNextWorkerNodeKey (): number {
let minWorkerElu = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerUsage = workerNode.usage
this.nextWorkerNodeKey = workerNodeKey
}
}
+ return this.nextWorkerNodeKey
}
}
/** @inheritDoc */
public choose (): number {
- this.leastUsedNextWorkerNodeKey()
- return this.nextWorkerNodeKey
+ return this.leastUsedNextWorkerNodeKey()
}
/** @inheritDoc */
return true
}
- private leastUsedNextWorkerNodeKey (): void {
+ private leastUsedNextWorkerNodeKey (): number {
let minNumberOfTasks = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTaskStatistics = workerNode.usage.tasks
this.nextWorkerNodeKey = workerNodeKey
}
}
+ return this.nextWorkerNodeKey
}
}
return true
}
- private roundRobinNextWorkerNodeKey (): void {
+ private roundRobinNextWorkerNodeKey (): number {
this.nextWorkerNodeKey =
this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
? 0
: this.nextWorkerNodeKey + 1
+ return this.nextWorkerNodeKey
}
}
*/
export interface StrategyPolicy {
/**
- * Expects direct usage of dynamic worker.
+ * Expects direct usage of the newly created dynamic worker.
*/
readonly useDynamicWorker: boolean
}
return true
}
- private weightedRoundRobinNextWorkerNodeKey (): void {
+ private weightedRoundRobinNextWorkerNodeKey (): number {
const workerVirtualTaskRunTime = this.workerVirtualTaskRunTime
const workerWeight =
this.opts.weights?.[this.nextWorkerNodeKey] ?? this.defaultWorkerWeight
: this.nextWorkerNodeKey + 1
this.workerVirtualTaskRunTime = 0
}
+ return this.nextWorkerNodeKey
}
}
*/
readonly resetUsage: () => void
/**
- * Gets task usage statistics.
+ * Gets task worker usage statistics.
*/
readonly getTaskWorkerUsage: (name: string) => WorkerUsage | undefined
}