repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into interleaved-weighted-round-robin-worker-choice-strategy
[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 b0750949749de7f2d22ec0c97733b2f3ea5ec8b9..a0553fcb81ace9c910b1ecd755b9c123b640f362 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
@@
-50,7
+50,7
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
- this.
checkOption
s(this.opts)
+ this.
setRequiredStatistic
s(this.opts)
this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
}
this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
}
@@
-61,16
+61,21
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
return true
}
return true
}
+ /** @inheritDoc */
+ public update (): boolean {
+ return true
+ }
+
/** @inheritDoc */
public choose (): number {
const chosenWorkerNodeKey = this.currentWorkerNodeId
/** @inheritDoc */
public choose (): number {
const chosenWorkerNodeKey = this.currentWorkerNodeId
- const worker
TaskRunTime = this.workerVirtualTaskRunTime ?? 0
- const worker
Task
Weight =
+ const worker
VirtualTaskRunTime = this.workerVirtualTaskRunTime
+ const workerWeight =
this.opts.weights?.[chosenWorkerNodeKey] ?? this.defaultWorkerWeight
this.opts.weights?.[chosenWorkerNodeKey] ?? this.defaultWorkerWeight
- if (worker
TaskRunTime < workerTask
Weight) {
+ if (worker
VirtualTaskRunTime < worker
Weight) {
this.workerVirtualTaskRunTime =
this.workerVirtualTaskRunTime =
- workerTaskRunTime +
-
(this.getWorkerVirtualTaskRunTime(chosenWorkerNodeKey) ?? 0
)
+ worker
Virtual
TaskRunTime +
+
this.getWorkerTaskRunTime(chosenWorkerNodeKey
)
} else {
this.currentWorkerNodeId =
this.currentWorkerNodeId === this.pool.workerNodes.length - 1
} else {
this.currentWorkerNodeId =
this.currentWorkerNodeId === this.pool.workerNodes.length - 1
@@
-86,23
+91,14
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
if (this.currentWorkerNodeId === workerNodeKey) {
if (this.pool.workerNodes.length === 0) {
this.currentWorkerNodeId = 0
if (this.currentWorkerNodeId === workerNodeKey) {
if (this.pool.workerNodes.length === 0) {
this.currentWorkerNodeId = 0
- } else {
- this.currentWorkerNodeId =
- this.currentWorkerNodeId > this.pool.workerNodes.length - 1
- ? this.pool.workerNodes.length - 1
- : this.currentWorkerNodeId
+ } else if (this.currentWorkerNodeId > this.pool.workerNodes.length - 1) {
+ this.currentWorkerNodeId = this.pool.workerNodes.length - 1
}
this.workerVirtualTaskRunTime = 0
}
return true
}
}
this.workerVirtualTaskRunTime = 0
}
return true
}
- private getWorkerVirtualTaskRunTime (workerNodeKey: number): number {
- return this.requiredStatistics.medRunTime
- ? this.pool.workerNodes[workerNodeKey].tasksUsage.medRunTime
- : this.pool.workerNodes[workerNodeKey].tasksUsage.avgRunTime
- }
-
private computeDefaultWorkerWeight (): number {
let cpusCycleTimeWeight = 0
for (const cpu of cpus()) {
private computeDefaultWorkerWeight (): number {
let cpusCycleTimeWeight = 0
for (const cpu of cpus()) {