fix: handle properly small or zero `tasksStealingRatio`
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 30 Aug 2024 13:22:40 +0000 (15:22 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 30 Aug 2024 13:22:40 +0000 (15:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts

index daef94341ae50c1c8235b0dba8f1d97dcddc1f7c..098ed23391c8a101953459e4d458df0b289753c2 100644 (file)
@@ -240,8 +240,9 @@ export abstract class AbstractPool<
     if (
       this.cannotStealTask() ||
       this.backPressure ||
+      this.opts.tasksQueueOptions?.tasksStealingRatio === 0 ||
       (this.info.stealingWorkerNodes ?? 0) >
-        Math.round(
+        Math.ceil(
           this.workerNodes.length *
             // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
             this.opts.tasksQueueOptions!.tasksStealingRatio!
@@ -299,8 +300,9 @@ export abstract class AbstractPool<
     if (
       !workerNode.info.continuousStealing &&
       (this.cannotStealTask() ||
+        this.opts.tasksQueueOptions?.tasksStealingRatio === 0 ||
         (this.info.stealingWorkerNodes ?? 0) >
-          Math.round(
+          Math.ceil(
             this.workerNodes.length *
               // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
               this.opts.tasksQueueOptions!.tasksStealingRatio!