Skip to content

Commit 7975318

Browse files
committed
Show total CPU as raw core count instead of percentage
Per review feedback: the Total row now displays a raw core count (e.g. 3.5 = 3.5 cores busy) while per-worker rows keep showing the familiar 0-400% style. Uses HTMLTemplateFormatter with a hidden _is_total column for conditional rendering in the same Bokeh DataTable column.
1 parent 28c7c52 commit 7975318

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

distributed/dashboard/components/scheduler.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4076,6 +4076,7 @@ def __init__(self, scheduler, **kwargs):
40764076
"host_disk_io.read_bps",
40774077
"host_disk_io.write_bps",
40784078
"cpu_fraction",
4079+
"_is_total",
40794080
]
40804081
workers = self.scheduler.workers.values()
40814082
self.extra_names = sorted(
@@ -4128,7 +4129,10 @@ def __init__(self, scheduler, **kwargs):
41284129
}
41294130

41304131
formatters = {
4131-
"cpu": NumberFormatter(format="0 %"),
4132+
"cpu": HTMLTemplateFormatter(
4133+
template='<% if (_is_total) { %><%= (value).toFixed(1) %>'
4134+
'<% } else { %><%= Math.round(value * 100) %> %<% } %>'
4135+
),
41324136
"memory_percent": NumberFormatter(format="0.0 %"),
41334137
"memory": NumberFormatter(format="0.0 b"),
41344138
"memory_limit": NumberFormatter(format="0.0 b"),
@@ -4281,11 +4285,15 @@ def update(self):
42814285
data["cpu"][-1] = ws.metrics["cpu"] / 100.0
42824286
data["cpu_fraction"][-1] = ws.metrics["cpu"] / 100.0 / ws.nthreads
42834287
data["nthreads"][-1] = ws.nthreads
4288+
data["_is_total"][-1] = False
42844289

42854290
for name in self.names + self.extra_names:
42864291
if name == "name":
42874292
data[name].insert(0, f"Total ({len(data[name])})")
42884293
continue
4294+
if name == "_is_total":
4295+
data[name].insert(0, True)
4296+
continue
42894297
try:
42904298
if len(self.scheduler.workers) == 0:
42914299
total_data = None
@@ -4308,7 +4316,6 @@ def update(self):
43084316
total_data = (
43094317
sum(ws.metrics["cpu"] for ws in self.scheduler.workers.values())
43104318
/ 100
4311-
/ sum(ws.nthreads for ws in self.scheduler.workers.values())
43124319
)
43134320
elif name == "cpu_fraction":
43144321
total_data = (

distributed/dashboard/tests/test_scheduler_bokeh.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,19 @@ 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)
567+
# Total CPU should show raw core count (sum of all worker CPU / 100)
568568
cpu = wt.source.data["cpu"]
569-
total_nthreads = sum(ws.nthreads for ws in s.workers.values())
570569
expected_cpu_total = (
571-
sum(ws.metrics["cpu"] for ws in s.workers.values()) / 100 / total_nthreads
570+
sum(ws.metrics["cpu"] for ws in s.workers.values()) / 100
572571
)
573572
assert cpu[0] == expected_cpu_total
574573

574+
# _is_total flag should be set correctly
575+
is_total = wt.source.data["_is_total"]
576+
assert is_total[0] is True
577+
assert is_total[1] is False
578+
assert is_total[2] is False
579+
575580

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

0 commit comments

Comments
 (0)