repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: add median task run time statistic
[poolifier.git]
/
src
/
pools
/
selection-strategies
/
weighted-round-robin-worker-choice-strategy.ts
diff --git
a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
index a8848f14ee80570f7c2d9e294d9d3552cfec3757..96b5867b5bfb1db98f8a8afd4505b5c24da75505 100644
(file)
--- a/
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
+++ b/
src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts
@@
-25,15
+25,16
@@
interface TaskRunTime {
*/
export class WeightedRoundRobinWorkerChoiceStrategy<
Worker extends IPoolWorker,
*/
export class WeightedRoundRobinWorkerChoiceStrategy<
Worker extends IPoolWorker,
- Data,
- Response
+ Data
= unknown
,
+ Response
= unknown
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
>
extends AbstractWorkerChoiceStrategy<Worker, Data, Response>
- implements IWorkerChoiceStrategy
<Worker, Data, Response>
{
- /**
{@inheritDoc}
*/
+ implements IWorkerChoiceStrategy {
+ /**
@inheritDoc
*/
public readonly requiredStatistics: RequiredStatistics = {
runTime: true,
public readonly requiredStatistics: RequiredStatistics = {
runTime: true,
- avgRunTime: true
+ avgRunTime: true,
+ medRunTime: false
}
/**
}
/**
@@
-63,7
+64,7
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
this.initWorkersTaskRunTime()
}
this.initWorkersTaskRunTime()
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
public reset (): boolean {
this.currentWorkerId = 0
this.workersTaskRunTime.clear()
public reset (): boolean {
this.currentWorkerId = 0
this.workersTaskRunTime.clear()
@@
-71,7
+72,7
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
return true
}
return true
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
public choose (): number {
const chosenWorkerKey = this.currentWorkerId
if (this.isDynamicPool && !this.workersTaskRunTime.has(chosenWorkerKey)) {
public choose (): number {
const chosenWorkerKey = this.currentWorkerId
if (this.isDynamicPool && !this.workersTaskRunTime.has(chosenWorkerKey)) {
@@
-99,13
+100,17
@@
export class WeightedRoundRobinWorkerChoiceStrategy<
return chosenWorkerKey
}
return chosenWorkerKey
}
- /**
{@inheritDoc}
*/
+ /**
@inheritDoc
*/
public remove (workerKey: number): boolean {
if (this.currentWorkerId === workerKey) {
public remove (workerKey: number): boolean {
if (this.currentWorkerId === workerKey) {
- this.currentWorkerId =
- this.currentWorkerId > this.pool.workers.length - 1
- ? this.pool.workers.length - 1
- : this.currentWorkerId
+ if (this.pool.workers.length === 0) {
+ this.currentWorkerId = 0
+ } else {
+ this.currentWorkerId =
+ this.currentWorkerId > this.pool.workers.length - 1
+ ? this.pool.workers.length - 1
+ : this.currentWorkerId
+ }
}
const workerDeleted = this.workersTaskRunTime.delete(workerKey)
for (const [key, value] of this.workersTaskRunTime) {
}
const workerDeleted = this.workersTaskRunTime.delete(workerKey)
for (const [key, value] of this.workersTaskRunTime) {