repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: ensure event is emitted before task promise rejection
[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 86a1ef23f1871ca85c0376db73b3517666e977ba..aaa6c21dc0f3dc7654a4b4d7986d44f809ef96b0 100644
(file)
--- a/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
@@
-27,7
+27,7
@@
export class LeastUsedWorkerChoiceStrategy<
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
) {
super(pool, opts)
- this.set
RequiredStatistic
s(this.opts)
+ this.set
TaskStatisticsRequirement
s(this.opts)
}
/** @inheritDoc */
}
/** @inheritDoc */
@@
-42,23
+42,22
@@
export class LeastUsedWorkerChoiceStrategy<
/** @inheritDoc */
public choose (): number {
/** @inheritDoc */
public choose (): number {
- const freeWorkerNodeKey = this.findFreeWorkerNodeKey()
- if (freeWorkerNodeKey !== -1) {
- return freeWorkerNodeKey
- }
let minNumberOfTasks = Infinity
let minNumberOfTasks = Infinity
- let leastUsedWorkerNodeKey!: number
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
- const tasksUsage = workerNode.tasksUsage
- const workerTasks = tasksUsage.ran + tasksUsage.running
+ const workerTaskStatistics = workerNode.workerUsage.tasks
+ const workerTasks =
+ workerTaskStatistics.executed +
+ workerTaskStatistics.executing +
+ workerTaskStatistics.queued
if (workerTasks === 0) {
if (workerTasks === 0) {
- return workerNodeKey
+ this.nextWorkerNodeId = workerNodeKey
+ break
} else if (workerTasks < minNumberOfTasks) {
minNumberOfTasks = workerTasks
} else if (workerTasks < minNumberOfTasks) {
minNumberOfTasks = workerTasks
-
leastUsedWorkerNodeKey
= workerNodeKey
+
this.nextWorkerNodeId
= workerNodeKey
}
}
}
}
- return
leastUsedWorkerNodeKey
+ return
this.nextWorkerNodeId
}
/** @inheritDoc */
}
/** @inheritDoc */