repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge dependabot/npm_and_yarn/examples/typescript/http-server-pool/fastify-worker_thr...
[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 e8a7218e160879bcaa97399d78a3b39ff7857bc1..d20c32174cc553c01b120fdd055217218fc4c314 100644
(file)
--- a/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
@@
-41,8
+41,10
@@
export class LeastUsedWorkerChoiceStrategy<
}
/** @inheritDoc */
}
/** @inheritDoc */
- public choose (): number {
- return this.leastUsedNextWorkerNodeKey()
+ public choose (): number | undefined {
+ this.setPreviousWorkerNodeKey(this.nextWorkerNodeKey)
+ this.nextWorkerNodeKey = this.leastUsedNextWorkerNodeKey()
+ return this.nextWorkerNodeKey
}
/** @inheritDoc */
}
/** @inheritDoc */
@@
-50,7
+52,8
@@
export class LeastUsedWorkerChoiceStrategy<
return true
}
return true
}
- private leastUsedNextWorkerNodeKey (): number {
+ private leastUsedNextWorkerNodeKey (): number | undefined {
+ let chosenWorkerNodeKey: number | undefined
let minNumberOfTasks = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTaskStatistics = workerNode.usage.tasks
let minNumberOfTasks = Infinity
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
const workerTaskStatistics = workerNode.usage.tasks
@@
-58,17
+61,14
@@
export class LeastUsedWorkerChoiceStrategy<
workerTaskStatistics.executed +
workerTaskStatistics.executing +
workerTaskStatistics.queued
workerTaskStatistics.executed +
workerTaskStatistics.executing +
workerTaskStatistics.queued
- if (
this.isWorkerNodeReady(workerNodeKey) &&
workerTasks === 0) {
-
this.next
WorkerNodeKey = workerNodeKey
+ if (workerTasks === 0) {
+
chosen
WorkerNodeKey = workerNodeKey
break
break
- } else if (
- this.isWorkerNodeReady(workerNodeKey) &&
- workerTasks < minNumberOfTasks
- ) {
+ } else if (workerTasks < minNumberOfTasks) {
minNumberOfTasks = workerTasks
minNumberOfTasks = workerTasks
-
this.next
WorkerNodeKey = workerNodeKey
+
chosen
WorkerNodeKey = workerNodeKey
}
}
}
}
- return
this.next
WorkerNodeKey
+ return
chosen
WorkerNodeKey
}
}
}
}