repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build: update volta node.js version
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
weighted-round-robin-worker-choice-strategy.ts
diff --git
a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
index 75e278bc407d704069e946be11a899cdfadaf8a7..fc6f48cf2632a89e0fa1de1afe198ff37eb2cdb7 100644
(file)
--- a/
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
@@
-4,6
+4,7
@@
import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
+ StrategyPolicy,
TaskStatisticsRequirements,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
TaskStatisticsRequirements,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
@@
-23,21
+24,30
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
+ /** @inheritDoc */
+ public readonly strategyPolicy: StrategyPolicy = {
+ useDynamicWorker: true
+ }
+
/** @inheritDoc */
public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
/** @inheritDoc */
public readonly taskStatisticsRequirements: TaskStatisticsRequirements = {
- runTime: true,
- avgRunTime: true,
- medRunTime: false,
- waitTime: false,
- avgWaitTime: false,
- medWaitTime: false,
- elu: false
+ runTime: {
+ aggregate: true,
+ average: true,
+ median: false
+ },
+ waitTime: {
+ aggregate: false,
+ average: false,
+ median: false
+ },
+ elu: {
+ aggregate: false,
+ average: false,
+ median: false
+ }
}
}
- /**
- * Worker node id where the current task will be submitted.
- */
- private currentWorkerNodeId: number = 0
/**
* Default worker weight.
*/
/**
* Default worker weight.
*/
@@
-53,13
+63,13
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
- this.setTaskStatistics(this.opts)
+ this.setTaskStatistics
Requirements
(this.opts)
this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
}
/** @inheritDoc */
public reset (): boolean {
this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
}
/** @inheritDoc */
public reset (): boolean {
- this.
curren
tWorkerNodeId = 0
+ this.
nex
tWorkerNodeId = 0
this.workerVirtualTaskRunTime = 0
return true
}
this.workerVirtualTaskRunTime = 0
return true
}
@@
-71,7
+81,7
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
/** @inheritDoc */
public choose (): number {
/** @inheritDoc */
public choose (): number {
- const chosenWorkerNodeKey = this.
curren
tWorkerNodeId
+ const chosenWorkerNodeKey = this.
nex
tWorkerNodeId
const workerVirtualTaskRunTime = this.workerVirtualTaskRunTime
const workerWeight =
this.opts.weights?.[chosenWorkerNodeKey] ?? this.defaultWorkerWeight
const workerVirtualTaskRunTime = this.workerVirtualTaskRunTime
const workerWeight =
this.opts.weights?.[chosenWorkerNodeKey] ?? this.defaultWorkerWeight
@@
-80,10
+90,10
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
workerVirtualTaskRunTime +
this.getWorkerTaskRunTime(chosenWorkerNodeKey)
} else {
workerVirtualTaskRunTime +
this.getWorkerTaskRunTime(chosenWorkerNodeKey)
} else {
- this.
curren
tWorkerNodeId =
- this.
curren
tWorkerNodeId === this.pool.workerNodes.length - 1
+ this.
nex
tWorkerNodeId =
+ this.
nex
tWorkerNodeId === this.pool.workerNodes.length - 1
? 0
? 0
- : this.
curren
tWorkerNodeId + 1
+ : this.
nex
tWorkerNodeId + 1
this.workerVirtualTaskRunTime = 0
}
return chosenWorkerNodeKey
this.workerVirtualTaskRunTime = 0
}
return chosenWorkerNodeKey
@@
-91,11
+101,11
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
/** @inheritDoc */
public remove (workerNodeKey: number): boolean {
/** @inheritDoc */
public remove (workerNodeKey: number): boolean {
- if (this.
curren
tWorkerNodeId === workerNodeKey) {
+ if (this.
nex
tWorkerNodeId === workerNodeKey) {
if (this.pool.workerNodes.length === 0) {
if (this.pool.workerNodes.length === 0) {
- this.
curren
tWorkerNodeId = 0
- } else if (this.
curren
tWorkerNodeId > this.pool.workerNodes.length - 1) {
- this.
curren
tWorkerNodeId = this.pool.workerNodes.length - 1
+ this.
nex
tWorkerNodeId = 0
+ } else if (this.
nex
tWorkerNodeId > this.pool.workerNodes.length - 1) {
+ this.
nex
tWorkerNodeId = this.pool.workerNodes.length - 1
}
this.workerVirtualTaskRunTime = 0
}
}
this.workerVirtualTaskRunTime = 0
}