From 8bd0556f30713198367ca520d242b662f5fe147a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 9 May 2024 16:55:44 +0200 Subject: [PATCH] fix: off-by-one stolen tasks accounting task function worker usage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 2f91df9d..10c99171 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1656,17 +1656,15 @@ export abstract class AbstractPool< this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) && workerNode.getTaskFunctionWorkerUsage(taskName) != null ) { - const taskFunctionWorkerUsage = - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - workerNode.getTaskFunctionWorkerUsage(taskName)! - ++taskFunctionWorkerUsage.tasks.stolen + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + ++workerNode.getTaskFunctionWorkerUsage(taskName)!.tasks.stolen } } private updateTaskSequentiallyStolenStatisticsWorkerUsage ( workerNodeKey: number, taskName: string, - previousStolenTaskName: string + previousTaskName?: string ): void { const workerNode = this.workerNodes[workerNodeKey] // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition @@ -1679,13 +1677,15 @@ export abstract class AbstractPool< this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) && taskFunctionWorkerUsage != null && (taskFunctionWorkerUsage.tasks.sequentiallyStolen === 0 || - (previousStolenTaskName === taskName && + (previousTaskName != null && + previousTaskName === taskName && taskFunctionWorkerUsage.tasks.sequentiallyStolen > 0)) ) { ++taskFunctionWorkerUsage.tasks.sequentiallyStolen } else if ( this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) && - taskFunctionWorkerUsage != null + taskFunctionWorkerUsage != null && + taskFunctionWorkerUsage.tasks.sequentiallyStolen > 0 ) { taskFunctionWorkerUsage.tasks.sequentiallyStolen = 0 } @@ -1704,10 +1704,10 @@ export abstract class AbstractPool< this.shallUpdateTaskFunctionWorkerUsage(workerNodeKey) && workerNode.getTaskFunctionWorkerUsage(taskName) != null ) { - const taskFunctionWorkerUsage = - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - workerNode.getTaskFunctionWorkerUsage(taskName)! - taskFunctionWorkerUsage.tasks.sequentiallyStolen = 0 + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + workerNode.getTaskFunctionWorkerUsage( + taskName + )!.tasks.sequentiallyStolen = 0 } } @@ -1759,13 +1759,12 @@ export abstract class AbstractPool< } workerInfo.stealing = true const stolenTask = this.workerNodeStealTask(workerNodeKey) - if (stolenTask != null && previousStolenTask != null) { + if (stolenTask != null) { this.updateTaskSequentiallyStolenStatisticsWorkerUsage( workerNodeKey, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion stolenTask.name!, - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - previousStolenTask.name! + previousStolenTask?.name ) } sleep(exponentialDelay(workerNodeTasksUsage.sequentiallyStolen)) -- 2.34.1