Repository: dask/distributed

Issue:
Rename "nbytes" chart to "worker memory"
The current chart in the dashboard that is named "nbytes" should probably be renamed to something else.  I suggest "worker memory", which I think is more easily identifiable


Discussion:
on it

Resolving patch:
diff --git a/distributed/dashboard/components/scheduler.py b/distributed/dashboard/components/scheduler.py
--- a/distributed/dashboard/components/scheduler.py
+++ b/distributed/dashboard/components/scheduler.py
@@ -228,8 +228,8 @@ def update(self):
         self.source.data.update({"left": x[:-1], "right": x[1:], "top": counts})
 
 
-def _nbytes_color(current: int, limit: int) -> str:
-    """Dynamic color used by NBytes and NBytesCluster"""
+def _memory_color(current: int, limit: int) -> str:
+    """Dynamic color used by WorkersMemory and ClusterMemory"""
     if limit and current > limit:
         return "red"
     elif limit and current > limit / 2:
@@ -238,7 +238,7 @@ def _nbytes_color(current: int, limit: int) -> str:
         return "blue"
 
 
-class NBytesCluster(DashboardComponent):
+class ClusterMemory(DashboardComponent):
     """Total memory usage on the cluster"""
 
     def __init__(self, scheduler, width=600, **kwargs):
@@ -262,9 +262,9 @@ def __init__(self, scheduler, width=600, **kwargs):
             self.root = figure(
                 title="Bytes stored on cluster",
                 tools="",
-                id="bk-nbytes-cluster-worker-plot",
+                id="bk-cluster-memory-plot",
                 width=int(width / 2),
-                name="nbytes_cluster",
+                name="cluster_memory",
                 **kwargs,
             )
             rect = self.root.rect(
@@ -322,7 +322,7 @@ def update(self):
         with log_errors():
             limit = sum(ws.memory_limit for ws in self.scheduler.workers.values())
             meminfo = self.scheduler.memory
-            color = _nbytes_color(meminfo.process, limit)
+            color = _memory_color(meminfo.process, limit)
 
             width = [
                 meminfo.managed_in_memory,
@@ -356,7 +356,7 @@ def update(self):
             update(self.source, result)
 
 
-class NBytes(DashboardComponent):
+class WorkersMemory(DashboardComponent):
     """Memory usage for single workers"""
 
     def __init__(self, scheduler, width=600, **kwargs):
@@ -382,9 +382,9 @@ def __init__(self, scheduler, width=600, **kwargs):
             self.root = figure(
                 title="Bytes stored per worker",
                 tools="",
-                id="bk-nbytes-worker-plot",
+                id="bk-workers-memory-plot",
                 width=int(width / 2),
-                name="nbytes_workers",
+                name="workers_memory",
                 **kwargs,
             )
             rect = self.root.rect(
@@ -472,7 +472,7 @@ def quadlist(i) -> list:
                 max_limit = max(
                     max_limit, limit, meminfo.process + meminfo.managed_spilled
                 )
-                color_i = _nbytes_color(meminfo.process, limit)
+                color_i = _memory_color(meminfo.process, limit)
 
                 width += [
                     meminfo.managed_in_memory,
@@ -517,7 +517,7 @@ def quadlist(i) -> list:
             update(self.source, result)
 
 
-class NBytesHistogram(DashboardComponent):
+class WorkersMemoryHistogram(DashboardComponent):
     """Histogram of memory usage, showing how many workers there are in each bucket of
     usage. Replaces the per-worker graph when there are >= 50 workers.
     """
@@ -532,8 +532,8 @@ def __init__(self, scheduler, **kwargs):
 
             self.root = figure(
                 title="Bytes stored per worker (Histogram)",
-                name="nbytes_workers",
-                id="bk-nbytes-histogram-plot",
+                name="workers_memory",
+                id="bk-workers-memory-histogram-plot",
                 y_axis_label="frequency",
                 tools="",
                 **kwargs,
@@ -2800,27 +2800,29 @@ def tg_graph_doc(scheduler, extra, doc):
 
 def status_doc(scheduler, extra, doc):
     with log_errors():
-        nbytes_cluster = NBytesCluster(scheduler, sizing_mode="stretch_both")
-        nbytes_cluster.update()
-        add_periodic_callback(doc, nbytes_cluster, 100)
-        doc.add_root(nbytes_cluster.root)
+        cluster_memory = ClusterMemory(scheduler, sizing_mode="stretch_both")
+        cluster_memory.update()
+        add_periodic_callback(doc, cluster_memory, 100)
+        doc.add_root(cluster_memory.root)
 
         if len(scheduler.workers) < 50:
-            nbytes_workers = NBytes(scheduler, sizing_mode="stretch_both")
+            workers_memory = WorkersMemory(scheduler, sizing_mode="stretch_both")
             processing = CurrentLoad(scheduler, sizing_mode="stretch_both")
             processing_root = processing.processing_figure
-            processing_root.y_range = nbytes_workers.root.y_range
+            processing_root.y_range = workers_memory.root.y_range
         else:
-            nbytes_workers = NBytesHistogram(scheduler, sizing_mode="stretch_both")
+            workers_memory = WorkersMemoryHistogram(
+                scheduler, sizing_mode="stretch_both"
+            )
             processing = ProcessingHistogram(scheduler, sizing_mode="stretch_both")
             processing_root = processing.root
-            row(nbytes_workers.root, processing.root, sizing_mode="stretch_both")
+            row(workers_memory.root, processing.root, sizing_mode="stretch_both")
 
-        nbytes_workers.update()
+        workers_memory.update()
         processing.update()
-        add_periodic_callback(doc, nbytes_workers, 100)
+        add_periodic_callback(doc, workers_memory, 100)
         add_periodic_callback(doc, processing, 100)
-        doc.add_root(nbytes_workers.root)
+        doc.add_root(workers_memory.root)
         doc.add_root(processing_root)
 
         task_stream = TaskStream(
diff --git a/distributed/dashboard/scheduler.py b/distributed/dashboard/scheduler.py
--- a/distributed/dashboard/scheduler.py
+++ b/distributed/dashboard/scheduler.py
@@ -14,17 +14,17 @@
     AggregateAction,
     BandwidthTypes,
     BandwidthWorkers,
+    ClusterMemory,
     ComputePerKey,
     CurrentLoad,
     MemoryByKey,
-    NBytes,
-    NBytesCluster,
     Occupancy,
     SystemMonitor,
     TaskGraph,
     TaskGroupGraph,
     TaskProgress,
     TaskStream,
+    WorkersMemory,
     WorkerTable,
     events_doc,
     graph_doc,
@@ -62,8 +62,13 @@
     "/individual-progress": individual_doc(TaskProgress, 100, height=160),
     "/individual-graph": individual_doc(TaskGraph, 200),
     "/individual-groups": individual_doc(TaskGroupGraph, 200),
-    "/individual-nbytes": individual_doc(NBytes, 100),
-    "/individual-nbytes-cluster": individual_doc(NBytesCluster, 100),
+    "/individual-workers-memory": individual_doc(WorkersMemory, 100),
+    "/individual-cluster-memory": individual_doc(ClusterMemory, 100),
+    # Temporary backwards compatibility with dask-labextension
+    # See https://github.com/dask/dask-labextension/issues/198
+    "/individual-nbytes": individual_doc(WorkersMemory, 100),
+    "/individual-nbytes-cluster": individual_doc(ClusterMemory, 100),
+    # End backwards compatibility
     "/individual-cpu": individual_doc(CurrentLoad, 100, fig_attr="cpu_figure"),
     "/individual-nprocessing": individual_doc(
         CurrentLoad, 100, fig_attr="processing_figure"


Test patch:
diff --git a/distributed/dashboard/tests/test_scheduler_bokeh.py b/distributed/dashboard/tests/test_scheduler_bokeh.py
--- a/distributed/dashboard/tests/test_scheduler_bokeh.py
+++ b/distributed/dashboard/tests/test_scheduler_bokeh.py
@@ -21,13 +21,11 @@
 from distributed.dashboard import scheduler
 from distributed.dashboard.components.scheduler import (
     AggregateAction,
+    ClusterMemory,
     ComputePerKey,
     CurrentLoad,
     Events,
     MemoryByKey,
-    NBytes,
-    NBytesCluster,
-    NBytesHistogram,
     Occupancy,
     ProcessingHistogram,
     ProfileServer,
@@ -38,6 +36,8 @@
     TaskGroupGraph,
     TaskProgress,
     TaskStream,
+    WorkersMemory,
+    WorkersMemoryHistogram,
     WorkerTable,
 )
 from distributed.dashboard.components.worker import Counters
@@ -276,8 +276,8 @@ async def test_ProcessingHistogram(c, s, a, b):
 
 
 @gen_cluster(client=True)
-async def test_NBytes(c, s, a, b):
-    cl = NBytes(s)
+async def test_WorkersMemory(c, s, a, b):
+    cl = WorkersMemory(s)
 
     futures = c.map(slowinc, range(10), delay=0.001)
     await wait(futures)
@@ -293,8 +293,8 @@ async def test_NBytes(c, s, a, b):
 
 
 @gen_cluster(client=True)
-async def test_NBytesCluster(c, s, a, b):
-    cl = NBytesCluster(s)
+async def test_ClusterMemory(c, s, a, b):
+    cl = ClusterMemory(s)
 
     futures = c.map(slowinc, range(10), delay=0.001)
     await wait(futures)
@@ -302,7 +302,7 @@ async def test_NBytesCluster(c, s, a, b):
     cl.update()
     d = dict(cl.source.data)
     llens = {len(l) for l in d.values()}
-    # Unlike NBytes, empty rects here aren't pruned away.
+    # Unlike WorkersMemory, empty rects here aren't pruned away.
     assert llens == {4}
     # There is definitely going to be managed_in_memory and
     # unmanaged_old; there may be unmanaged_new. There won't be managed_spilled.
@@ -311,8 +311,8 @@ async def test_NBytesCluster(c, s, a, b):
 
 
 @gen_cluster(client=True)
-async def test_NBytesHistogram(c, s, a, b):
-    nh = NBytesHistogram(s)
+async def test_WorkersMemoryHistogram(c, s, a, b):
+    nh = WorkersMemoryHistogram(s)
     nh.update()
     assert any(nh.source.data["top"] != 0)