From: Jérôme Benoit Date: Wed, 28 Aug 2024 10:29:39 +0000 (+0200) Subject: perf: reduce useless branching at pool info building X-Git-Tag: v4.2.7~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4a29667ae71425df81946f45951e90aef20986e9;p=poolifier.git perf: reduce useless branching at pool info building Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 35ac4a0f..a0c779c2 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -2044,9 +2044,6 @@ export abstract class AbstractPool< minSize: this.minimumNumberOfWorkers, ready: this.ready, started: this.started, - ...(this.opts.enableTasksQueue === true && { - backPressure: this.backPressure, - }), strategyRetries: this.workerChoiceStrategiesContext?.retriesCount ?? 0, type: this.type, version, @@ -2062,6 +2059,21 @@ export abstract class AbstractPool< this.isWorkerNodeBusy(workerNodeKey) ? accumulator + 1 : accumulator, 0 ), + executedTasks: this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + workerNode.usage.tasks.executed, + 0 + ), + executingTasks: this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + workerNode.usage.tasks.executing, + 0 + ), + failedTasks: this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + workerNode.usage.tasks.failed, + 0 + ), idleWorkerNodes: this.workerNodes.reduce( (accumulator, _, workerNodeKey) => this.isWorkerNodeIdle(workerNodeKey) ? accumulator + 1 : accumulator, @@ -2069,16 +2081,7 @@ export abstract class AbstractPool< ), workerNodes: this.workerNodes.length, ...(this.opts.enableTasksQueue === true && { - stealingWorkerNodes: this.workerNodes.reduce( - (accumulator, workerNode) => - workerNode.info.continuousStealing || - workerNode.info.backPressureStealing - ? accumulator + 1 - : accumulator, - 0 - ), - }), - ...(this.opts.enableTasksQueue === true && { + backPressure: this.backPressure, backPressureWorkerNodes: this.workerNodes.reduce( (accumulator, _, workerNodeKey) => this.isWorkerNodeBackPressured(workerNodeKey) @@ -2086,43 +2089,30 @@ export abstract class AbstractPool< : accumulator, 0 ), - }), - executedTasks: this.workerNodes.reduce( - (accumulator, workerNode) => - accumulator + workerNode.usage.tasks.executed, - 0 - ), - executingTasks: this.workerNodes.reduce( - (accumulator, workerNode) => - accumulator + workerNode.usage.tasks.executing, - 0 - ), - ...(this.opts.enableTasksQueue === true && { + maxQueuedTasks: this.workerNodes.reduce( + (accumulator, workerNode) => + accumulator + (workerNode.usage.tasks.maxQueued ?? 0), + 0 + ), queuedTasks: this.workerNodes.reduce( (accumulator, workerNode) => accumulator + workerNode.usage.tasks.queued, 0 ), - }), - ...(this.opts.enableTasksQueue === true && { - maxQueuedTasks: this.workerNodes.reduce( + stealingWorkerNodes: this.workerNodes.reduce( (accumulator, workerNode) => - accumulator + (workerNode.usage.tasks.maxQueued ?? 0), + workerNode.info.continuousStealing || + workerNode.info.backPressureStealing + ? accumulator + 1 + : accumulator, 0 ), - }), - ...(this.opts.enableTasksQueue === true && { stolenTasks: this.workerNodes.reduce( (accumulator, workerNode) => accumulator + workerNode.usage.tasks.stolen, 0 ), }), - failedTasks: this.workerNodes.reduce( - (accumulator, workerNode) => - accumulator + workerNode.usage.tasks.failed, - 0 - ), ...(this.workerChoiceStrategiesContext?.getTaskStatisticsRequirements() .runTime.aggregate === true && { runTime: {