repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
docs: refine benchmarks README
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
round-robin-worker-choice-strategy.ts
diff --git
a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
index 80e958a406fa2209ce1c20eded5b8e9b79e9ca0b..936925313f99e9bafa6c3bb8c0a71f7ad0c94fad 100644
(file)
--- a/
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/round-robin-worker-choice-strategy.ts
@@
-1,6
+1,12
@@
+import { DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS } from '../../utils'
+import type { IPool } from '../pool'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
import type { IWorker } from '../worker'
import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy'
-import type { IWorkerChoiceStrategy } from './selection-strategies-types'
+import type {
+ IWorkerChoiceStrategy,
+ StrategyPolicy,
+ WorkerChoiceStrategyOptions
+} from './selection-strategies-types'
/**
* Selects the next worker in a round robin fashion.
/**
* Selects the next worker in a round robin fashion.
@@
-16,17
+22,36
@@
export class RoundRobinWorkerChoiceStrategy<
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
implements IWorkerChoiceStrategy {
+ /** @inheritDoc */
+ public readonly strategyPolicy: StrategyPolicy = {
+ useDynamicWorker: true
+ }
+
/**
* Id of the next worker node.
*/
private nextWorkerNodeId: number = 0
/**
* Id of the next worker node.
*/
private nextWorkerNodeId: number = 0
+ /** @inheritDoc */
+ public constructor (
+ pool: IPool<Worker, Data, Response>,
+ opts: WorkerChoiceStrategyOptions = DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS
+ ) {
+ super(pool, opts)
+ this.setTaskStatisticsRequirements(this.opts)
+ }
+
/** @inheritDoc */
public reset (): boolean {
this.nextWorkerNodeId = 0
return true
}
/** @inheritDoc */
public reset (): boolean {
this.nextWorkerNodeId = 0
return true
}
+ /** @inheritDoc */
+ public update (): boolean {
+ return true
+ }
+
/** @inheritDoc */
public choose (): number {
const chosenWorkerNodeKey = this.nextWorkerNodeId
/** @inheritDoc */
public choose (): number {
const chosenWorkerNodeKey = this.nextWorkerNodeId
@@
-42,11
+67,8
@@
export class RoundRobinWorkerChoiceStrategy<
if (this.nextWorkerNodeId === workerNodeKey) {
if (this.pool.workerNodes.length === 0) {
this.nextWorkerNodeId = 0
if (this.nextWorkerNodeId === workerNodeKey) {
if (this.pool.workerNodes.length === 0) {
this.nextWorkerNodeId = 0
- } else {
- this.nextWorkerNodeId =
- this.nextWorkerNodeId > this.pool.workerNodes.length - 1
- ? this.pool.workerNodes.length - 1
- : this.nextWorkerNodeId
+ } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) {
+ this.nextWorkerNodeId = this.pool.workerNodes.length - 1
}
}
return true
}
}
return true