repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
docs: refine comments
[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..2805133092b651ec1efa9d71a5f2f209b0f260f8 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
@@
-1,9
+1,13
@@
import type { IWorker } from '../worker'
import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import type { IPool } from '../pool'
-import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
+import {
+ DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
+ 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'
@@
-13,8
+17,8
@@
import type {
* Loosely modeled after the weighted round robin queueing algorithm: https://en.wikipedia.org/wiki/Weighted_round_robin.
*
* @typeParam Worker - Type of worker which manages the strategy.
* Loosely modeled after the weighted round robin queueing algorithm: https://en.wikipedia.org/wiki/Weighted_round_robin.
*
* @typeParam Worker - Type of worker which manages the strategy.
- * @typeParam Data - Type of data sent to the worker. This can only be s
erializ
able data.
- * @typeParam Response - Type of execution response. This can only be s
erializ
able data.
+ * @typeParam Data - Type of data sent to the worker. This can only be s
tructured-clone
able data.
+ * @typeParam Response - Type of execution response. This can only be s
tructured-clone
able data.
*/
export class WeightedRoundRobinWorkerChoiceStrategy<
Worker extends IWorker,
*/
export class WeightedRoundRobinWorkerChoiceStrategy<
Worker extends IWorker,
@@
-23,21
+27,22
@@
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,
-
avgRunTim
e: true,
-
medRunTime: fals
e,
- waitTime: false,
-
avgWaitTime: false
,
-
medWaitTime: false
,
- elu:
false
+ runTime:
{
+
aggregat
e: true,
+
average: tru
e,
+ median: false
+
}
,
+
waitTime: DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS
,
+ elu:
DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS
}
}
- /**
- * Worker node id where the current task will be submitted.
- */
- private currentWorkerNodeId: number = 0
/**
* Default worker weight.
*/
/**
* Default worker weight.
*/
@@
-53,13
+58,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
+76,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
+85,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
+96,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
}