repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
test: less strict expectation for CI
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
interleaved-weighted-round-robin-worker-choice-strategy.ts
diff --git
a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts
b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts
index 7fba0f1b5dad0972af4ae9630b3c8565301a7863..0f718e9817159bd6aedb5012e3246786d4696f50 100644
(file)
--- a/
src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts
@@
-1,14
+1,11
@@
import type { IWorker } from '../worker'
import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import type { IPool } from '../pool'
-import {
- DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
- DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
-} from '../../utils'
+import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../../utils'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
-
TaskStatisticsRequirement
s,
-
WorkerChoiceStrategyOption
s
+
InternalWorkerChoiceStrategyOption
s,
+
TaskStatisticsRequirement
s
} from './selection-strategies-types'
/**
} from './selection-strategies-types'
/**
@@
-40,32
+37,26
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
* Round id.
*/
private roundId: number = 0
* Round id.
*/
private roundId: number = 0
- /**
- * Default worker weight.
- */
- private readonly defaultWorkerWeight: number
/**
* Round weights.
*/
/**
* Round weights.
*/
- private roundWeights: number[]
+ private roundWeights
!
: number[]
/**
* Worker node id.
*/
private workerNodeId: number = 0
/**
/**
* Worker node id.
*/
private workerNodeId: number = 0
/**
- * Worker virtual task runtime.
+ * Worker
node
virtual task runtime.
*/
*/
- private workerVirtualTaskRunTime: number = 0
+ private worker
Node
VirtualTaskRunTime: number = 0
/** @inheritDoc */
public constructor (
pool: IPool<Worker, Data, Response>,
/** @inheritDoc */
public constructor (
pool: IPool<Worker, Data, Response>,
- opts:
WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ opts:
InternalWorkerChoiceStrategyOptions
) {
super(pool, opts)
) {
super(pool, opts)
- this.setTaskStatisticsRequirements(this.opts)
- this.defaultWorkerWeight = this.computeDefaultWorkerWeight()
- this.roundWeights = this.getRoundWeights()
+ this.setOptions(this.opts)
}
/** @inheritDoc */
}
/** @inheritDoc */
@@
-73,7
+64,7
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
this.resetWorkerNodeKeyProperties()
this.roundId = 0
this.workerNodeId = 0
this.resetWorkerNodeKeyProperties()
this.roundId = 0
this.workerNodeId = 0
- this.workerVirtualTaskRunTime = 0
+ this.worker
Node
VirtualTaskRunTime = 0
return true
}
return true
}
@@
-98,19
+89,19
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
this.workerNodeId = workerNodeKey
if (
this.workerNodeId !== this.nextWorkerNodeKey &&
this.workerNodeId = workerNodeKey
if (
this.workerNodeId !== this.nextWorkerNodeKey &&
- this.workerVirtualTaskRunTime !== 0
+ this.worker
Node
VirtualTaskRunTime !== 0
) {
) {
- this.workerVirtualTaskRunTime = 0
+ this.worker
Node
VirtualTaskRunTime = 0
}
}
- const workerWeight =
- this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight
+ const workerWeight = this.opts.weights?.[workerNodeKey] as number
if (
if (
+ this.isWorkerNodeReady(workerNodeKey) &&
workerWeight >= this.roundWeights[roundIndex] &&
workerWeight >= this.roundWeights[roundIndex] &&
- this.workerVirtualTaskRunTime < workerWeight
+ this.worker
Node
VirtualTaskRunTime < workerWeight
) {
) {
- this.workerVirtualTaskRunTime =
- this.workerVirtualTaskRunTime +
- this.getWorkerTaskRunTime(workerNodeKey)
+ this.worker
Node
VirtualTaskRunTime =
+ this.worker
Node
VirtualTaskRunTime +
+ this.getWorker
Node
TaskRunTime(workerNodeKey)
this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
this.nextWorkerNodeKey = workerNodeKey
return this.nextWorkerNodeKey
this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
this.nextWorkerNodeKey = workerNodeKey
return this.nextWorkerNodeKey
@@
-156,18
+147,15
@@
export class InterleavedWeightedRoundRobinWorkerChoiceStrategy<
}
/** @inheritDoc */
}
/** @inheritDoc */
- public setOptions (opts: WorkerChoiceStrategyOptions): void {
+ public setOptions (opts:
Internal
WorkerChoiceStrategyOptions): void {
super.setOptions(opts)
this.roundWeights = this.getRoundWeights()
}
private getRoundWeights (): number[] {
super.setOptions(opts)
this.roundWeights = this.getRoundWeights()
}
private getRoundWeights (): number[] {
- if (this.opts.weights == null) {
- return [this.defaultWorkerWeight]
- }
return [
...new Set(
return [
...new Set(
- Object.values(this.opts.weights)
+ Object.values(this.opts.weights
as Record<number, number>
)
.slice()
.sort((a, b) => a - b)
)
.slice()
.sort((a, b) => a - b)
)