repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: some more edges cases in the worker choice strategy retries code
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
least-used-worker-choice-strategy.ts
diff --git
a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts
b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts
index e72efda2eb7db69411cc324e2e003c64fa08f529..1f7033214d6a4735c3064df290acc2ce48cb3e72 100644
(file)
--- a/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
@@
-4,6
+4,7
@@
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type {
IWorkerChoiceStrategy,
+ StrategyPolicy,
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
WorkerChoiceStrategyOptions
} from './selection-strategies-types'
@@
-21,6
+22,12
@@
export class LeastUsedWorkerChoiceStrategy<
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
+ /** @inheritDoc */
+ public readonly strategyPolicy: StrategyPolicy = {
+ dynamicWorkerUsage: false,
+ dynamicWorkerReady: true
+ }
+
/** @inheritDoc */
public constructor (
pool: IPool<Worker, Data, Response>,
/** @inheritDoc */
public constructor (
pool: IPool<Worker, Data, Response>,
@@
-41,8
+48,10
@@
export class LeastUsedWorkerChoiceStrategy<
}
/** @inheritDoc */
}
/** @inheritDoc */
- public choose (): number {
- return this.leastUsedNextWorkerNodeKey()
+ public choose (): number | undefined {
+ const chosenWorkerNodeKey = this.leastUsedNextWorkerNodeKey()
+ this.assignChosenWorkerNodeKey(chosenWorkerNodeKey)
+ return this.nextWorkerNodeKey
}
/** @inheritDoc */
}
/** @inheritDoc */
@@
-50,8
+59,9
@@
export class LeastUsedWorkerChoiceStrategy<
return true
}
return true
}
- private leastUsedNextWorkerNodeKey (): number {
+ private leastUsedNextWorkerNodeKey (): number
| undefined
{
let minNumberOfTasks = Infinity
let minNumberOfTasks = Infinity
+ let chosenWorkerNodeKey: number | undefined
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTaskStatistics = workerNode.usage.tasks
const workerTasks =
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTaskStatistics = workerNode.usage.tasks
const workerTasks =
@@
-59,16
+69,16
@@
export class LeastUsedWorkerChoiceStrategy<
workerTaskStatistics.executing +
workerTaskStatistics.queued
if (this.isWorkerNodeEligible(workerNodeKey) && workerTasks === 0) {
workerTaskStatistics.executing +
workerTaskStatistics.queued
if (this.isWorkerNodeEligible(workerNodeKey) && workerTasks === 0) {
-
this.next
WorkerNodeKey = workerNodeKey
+
chosen
WorkerNodeKey = workerNodeKey
break
} else if (
this.isWorkerNodeEligible(workerNodeKey) &&
workerTasks < minNumberOfTasks
) {
minNumberOfTasks = workerTasks
break
} else if (
this.isWorkerNodeEligible(workerNodeKey) &&
workerTasks < minNumberOfTasks
) {
minNumberOfTasks = workerTasks
-
this.next
WorkerNodeKey = workerNodeKey
+
chosen
WorkerNodeKey = workerNodeKey
}
}
}
}
- return
this.next
WorkerNodeKey
+ return
chosen
WorkerNodeKey
}
}
}
}