import { cpus } from 'node:os'
-import type { IPoolInternal } from '../pool-internal'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
- RequiredStatistics
+ RequiredStatistics,
+ WorkerChoiceStrategyOptions
} from './selection-strategies-types'
+import type { IPool } from '../pool'
/**
* Virtual task runtime.
* Constructs a worker choice strategy that selects with a weighted round robin scheduling algorithm.
*
* @param pool - The pool instance.
+ * @param opts - The worker choice strategy options.
*/
- public constructor (pool: IPoolInternal<Worker, Data, Response>) {
- super(pool)
+ public constructor (
+ pool: IPool<Worker, Data, Response>,
+ opts?: WorkerChoiceStrategyOptions
+ ) {
+ super(pool, opts)
this.defaultWorkerWeight = this.computeWorkerWeight()
this.initWorkersTaskRunTime()
}
}
private getWorkerVirtualTaskRunTime (workerNodeKey: number): number {
- return this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime
+ return this.requiredStatistics.medRunTime
+ ? this.pool.workerNodes[workerNodeKey].tasksUsage.medRunTime
+ : this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime
}
private computeWorkerWeight (): number {