feat: optimize worker choice strategies implementation
[poolifier.git] / src / pools / selection-strategies / weighted-round-robin-worker-choice-strategy.ts
index b023bfb0cd258641354c81c465c20fa9a3b0b309..b9b74b6cb96634f665628d1032fd0b37a83ddef9 100644 (file)
@@ -42,9 +42,9 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
    */
   private readonly defaultWorkerWeight: number
   /**
-   * Worker virtual task runtime.
+   * Worker node virtual task runtime.
    */
-  private workerVirtualTaskRunTime: number = 0
+  private workerNodeVirtualTaskRunTime: number = 0
 
   /** @inheritDoc */
   public constructor (
@@ -59,7 +59,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
   /** @inheritDoc */
   public reset (): boolean {
     this.resetWorkerNodeKeyProperties()
-    this.workerVirtualTaskRunTime = 0
+    this.workerNodeVirtualTaskRunTime = 0
     return true
   }
 
@@ -80,7 +80,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
       this.reset()
     }
     if (this.nextWorkerNodeKey === workerNodeKey) {
-      this.workerVirtualTaskRunTime = 0
+      this.workerNodeVirtualTaskRunTime = 0
       if (this.nextWorkerNodeKey > this.pool.workerNodes.length - 1) {
         this.nextWorkerNodeKey = this.pool.workerNodes.length - 1
       }
@@ -99,10 +99,10 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
       this.opts.weights?.[
         this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
       ] ?? this.defaultWorkerWeight
-    if (this.workerVirtualTaskRunTime < workerWeight) {
-      this.workerVirtualTaskRunTime =
-        this.workerVirtualTaskRunTime +
-        this.getWorkerTaskRunTime(
+    if (this.workerNodeVirtualTaskRunTime < workerWeight) {
+      this.workerNodeVirtualTaskRunTime =
+        this.workerNodeVirtualTaskRunTime +
+        this.getWorkerNodeTaskRunTime(
           this.nextWorkerNodeKey ?? this.previousWorkerNodeKey
         )
     } else {
@@ -110,7 +110,7 @@ export class WeightedRoundRobinWorkerChoiceStrategy<
         this.nextWorkerNodeKey === this.pool.workerNodes.length - 1
           ? 0
           : (this.nextWorkerNodeKey ?? this.previousWorkerNodeKey) + 1
-      this.workerVirtualTaskRunTime = 0
+      this.workerNodeVirtualTaskRunTime = 0
     }
     return this.nextWorkerNodeKey
   }