From: Jérôme Benoit Date: Thu, 24 Aug 2023 21:27:18 +0000 (+0200) Subject: fix: ensure task stealing respects the tasks queueing semantic X-Git-Tag: v2.6.35~20 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=2cb4ff45b1171d4978e7bfca62a04bb359042a68;p=poolifier.git fix: ensure task stealing respects the tasks queueing semantic Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index a6ffcbbb..062df077 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1253,18 +1253,14 @@ export abstract class AbstractPool< ...(sourceWorkerNode.popTask() as Task), workerId: destinationWorkerNode.info.id as number } - // Enqueue task for continuous task stealing - this.enqueueTask(destinationWorkerNodeKey, task) - // Avoid starvation if ( - this.tasksQueueSize(destinationWorkerNodeKey) > 0 && + this.tasksQueueSize(destinationWorkerNodeKey) === 0 && destinationWorkerNode.usage.tasks.executing < (this.opts.tasksQueueOptions?.concurrency as number) ) { - this.executeTask( - destinationWorkerNodeKey, - this.dequeueTask(destinationWorkerNodeKey) as Task - ) + this.executeTask(destinationWorkerNodeKey, task) + } else { + this.enqueueTask(destinationWorkerNodeKey, task) } break }