Skip to content

Commit 28c7c52

Browse files
committed
Fix Total CPU % on /workers tab to normalize by total nthreads
The WorkerTable's Total CPU % divided by len(workers) instead of sum(nthreads), producing incorrect values when workers have multiple threads (e.g., 400% instead of 50%). This aligns the "cpu" column with the already-correct "cpu_fraction" column, matching the same fix pattern as PR #3897 for memory_percent. Closes #8490
1 parent 4fb4814 commit 28c7c52

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

distributed/dashboard/components/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4308,7 +4308,7 @@ def update(self):
43084308
total_data = (
43094309
sum(ws.metrics["cpu"] for ws in self.scheduler.workers.values())
43104310
/ 100
4311-
/ len(self.scheduler.workers.values())
4311+
/ sum(ws.nthreads for ws in self.scheduler.workers.values())
43124312
)
43134313
elif name == "cpu_fraction":
43144314
total_data = (

distributed/dashboard/tests/test_scheduler_bokeh.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,14 @@ async def test_WorkerTable(c, s, a, b):
564564
assert all(nthreads)
565565
assert nthreads[0] == nthreads[1] + nthreads[2]
566566

567+
# Total CPU should be normalized by sum(nthreads), not len(workers)
568+
cpu = wt.source.data["cpu"]
569+
total_nthreads = sum(ws.nthreads for ws in s.workers.values())
570+
expected_cpu_total = (
571+
sum(ws.metrics["cpu"] for ws in s.workers.values()) / 100 / total_nthreads
572+
)
573+
assert cpu[0] == expected_cpu_total
574+
567575

568576
@gen_cluster(client=True)
569577
async def test_WorkerTable_custom_metrics(c, s, a, b):

0 commit comments

Comments
 (0)