- public choose (): Worker {
- const currentWorker = this.pool.workers[this.currentWorkerIndex]
- if (
- this.isDynamicPool === true &&
- this.workersTaskRunTime.has(currentWorker) === false
- ) {
- this.initWorkerTaskRunTime(currentWorker)
- }
- const workerVirtualTaskRunTime =
- this.getWorkerVirtualTaskRunTime(currentWorker) ?? 0
- const workerTaskWeight =
- this.workersTaskRunTime.get(currentWorker)?.weight ??
- this.defaultWorkerWeight
- if (this.currentWorkerIndex === this.previousWorkerIndex) {
- const workerTaskRunTime =
- (this.workersTaskRunTime.get(currentWorker)?.runTime ?? 0) +
- workerVirtualTaskRunTime
- this.setWorkerTaskRunTime(
- currentWorker,
- workerTaskWeight,
- workerTaskRunTime
- )
- } else {
- this.setWorkerTaskRunTime(currentWorker, workerTaskWeight, 0)
- }
- if (
- workerVirtualTaskRunTime <
- (this.workersTaskRunTime.get(currentWorker)?.weight ??
- this.defaultWorkerWeight)
- ) {
- this.previousWorkerIndex = this.currentWorkerIndex
- } else {
- this.previousWorkerIndex = this.currentWorkerIndex
- this.currentWorkerIndex =
- this.pool.workers.length - 1 === this.currentWorkerIndex
- ? 0
- : this.currentWorkerIndex + 1
- }
- return this.pool.workers[this.currentWorkerIndex]
+ public constructor (
+ pool: IPool<Worker, Data, Response>,
+ opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ ) {
+ super(pool, opts)
+ this.setTaskStatisticsRequirements(this.opts)
+ this.defaultWorkerWeight = this.computeDefaultWorkerWeight()