repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
build(deps-dev): apply updates
[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 528bca1dc683adf0ac25cdd8f53ba4a2737b2294..e8a7218e160879bcaa97399d78a3b39ff7857bc1 100644
(file)
--- a/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/least-used-worker-choice-strategy.ts
@@
-11,8
+11,8
@@
import type {
* Selects the least used worker.
*
* @typeParam Worker - Type of worker which manages the strategy.
* Selects the least used worker.
*
* @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 LeastUsedWorkerChoiceStrategy<
Worker extends IWorker,
*/
export class LeastUsedWorkerChoiceStrategy<
Worker extends IWorker,
@@
-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.setTaskStatistics(this.opts)
+ this.setTaskStatistics
Requirements
(this.opts)
}
/** @inheritDoc */
}
/** @inheritDoc */
@@
-42,30
+42,33
@@
export class LeastUsedWorkerChoiceStrategy<
/** @inheritDoc */
public choose (): number {
/** @inheritDoc */
public choose (): number {
- const freeWorkerNodeKey = this.findFreeWorkerNodeKey()
- if (freeWorkerNodeKey !== -1) {
- return freeWorkerNodeKey
- }
+ return this.leastUsedNextWorkerNodeKey()
+ }
+
+ /** @inheritDoc */
+ public remove (): boolean {
+ return true
+ }
+
+ private leastUsedNextWorkerNodeKey (): number {
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 workerTaskStatistics = workerNode.
workerU
sage.tasks
+ const workerTaskStatistics = workerNode.
u
sage.tasks
const workerTasks =
workerTaskStatistics.executed +
workerTaskStatistics.executing +
workerTaskStatistics.queued
const workerTasks =
workerTaskStatistics.executed +
workerTaskStatistics.executing +
workerTaskStatistics.queued
- if (workerTasks === 0) {
- return workerNodeKey
- } else if (workerTasks < minNumberOfTasks) {
+ if (this.isWorkerNodeReady(workerNodeKey) && workerTasks === 0) {
+ this.nextWorkerNodeKey = workerNodeKey
+ break
+ } else if (
+ this.isWorkerNodeReady(workerNodeKey) &&
+ workerTasks < minNumberOfTasks
+ ) {
minNumberOfTasks = workerTasks
minNumberOfTasks = workerTasks
-
leastUsed
WorkerNodeKey = workerNodeKey
+
this.next
WorkerNodeKey = workerNodeKey
}
}
}
}
- return leastUsedWorkerNodeKey
- }
-
- /** @inheritDoc */
- public remove (): boolean {
- return true
+ return this.nextWorkerNodeKey
}
}
}
}