From: Jérôme Benoit Date: Thu, 9 May 2024 14:55:44 +0000 (+0200) Subject: fix: off-by-one stolen tasks accounting task function worker usage X-Git-Tag: v4.0.5~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8bd0556f30713198367ca520d242b662f5fe147a;p=poolifier.git fix: off-by-one stolen tasks accounting task function worker usage Signed-off-by: Jérôme Benoit --- 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))