-
-
Notifications
You must be signed in to change notification settings - Fork 710
/
scheduler.py
4391 lines (3813 loc) · 144 KB
/
scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
import logging
import math
import operator
import os
from collections import OrderedDict, defaultdict
from collections.abc import Iterable
from datetime import datetime
from numbers import Number
from typing import Any, TypeVar
import numpy as np
from bokeh.core.properties import value, without_property_validation
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import (
AdaptiveTicker,
Arrow,
BasicTicker,
BoxSelectTool,
BoxZoomTool,
CDSView,
ColorBar,
ColumnDataSource,
CustomJSHover,
DataRange1d,
FactorRange,
GroupFilter,
HoverTool,
HTMLTemplateFormatter,
NumberFormatter,
NumeralTickFormatter,
OpenURL,
Panel,
PanTool,
Range1d,
ResetTool,
Tabs,
TapTool,
Title,
VeeHead,
WheelZoomTool,
)
from bokeh.models.widgets import DataTable, TableColumn
from bokeh.models.widgets.markups import Div
from bokeh.palettes import Viridis11
from bokeh.plotting import figure
from bokeh.themes import Theme
from bokeh.transform import cumsum, factor_cmap, linear_cmap, stack
from jinja2 import Environment, FileSystemLoader
from tlz import curry, pipe, valmap
from tlz.curried import concat, groupby, map
from tornado import escape
import dask
from dask import config
from dask.utils import (
format_bytes,
format_time,
funcname,
key_split,
parse_bytes,
parse_timedelta,
)
from distributed.core import Status
from distributed.dashboard.components import add_periodic_callback
from distributed.dashboard.components.shared import (
DashboardComponent,
ProfileServer,
ProfileTimePlot,
SystemMonitor,
)
from distributed.dashboard.utils import BOKEH_VERSION, PROFILING, transpose, update
from distributed.diagnostics.graph_layout import GraphLayout
from distributed.diagnostics.progress import GroupTiming
from distributed.diagnostics.progress_stream import color_of, progress_quads
from distributed.diagnostics.task_stream import TaskStreamPlugin
from distributed.diagnostics.task_stream import color_of as ts_color_of
from distributed.diagnostics.task_stream import colors as ts_color_lookup
from distributed.metrics import time
from distributed.scheduler import Scheduler
from distributed.utils import Log, log_errors
if dask.config.get("distributed.dashboard.export-tool"):
from distributed.dashboard.export_tool import ExportTool
else:
ExportTool = None # type: ignore
T = TypeVar("T")
logger = logging.getLogger(__name__)
env = Environment(
loader=FileSystemLoader(
os.path.join(os.path.dirname(__file__), "..", "..", "http", "templates")
)
)
BOKEH_THEME = Theme(
filename=os.path.join(os.path.dirname(__file__), "..", "theme.yaml")
)
TICKS_1024 = {"base": 1024, "mantissas": [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]}
XLABEL_ORIENTATION = -math.pi / 9 # slanted downwards 20 degrees
logos_dict = {
"numpy": "statics/images/numpy.png",
"pandas": "statics/images/pandas.png",
"builtins": "statics/images/python.png",
}
class Occupancy(DashboardComponent):
"""Occupancy (in time) per worker"""
@log_errors
def __init__(self, scheduler, **kwargs):
self.scheduler = scheduler
self.source = ColumnDataSource(
{
"occupancy": [0, 0],
"worker": ["a", "b"],
"x": [0.0, 0.1],
"y": [1, 2],
"ms": [1, 2],
"color": ["red", "blue"],
"escaped_worker": ["a", "b"],
}
)
self.root = figure(
title="Occupancy",
tools="",
toolbar_location="above",
id="bk-occupancy-plot",
x_axis_type="datetime",
min_border_bottom=50,
**kwargs,
)
rect = self.root.rect(
source=self.source, x="x", width="ms", y="y", height=0.9, color="color"
)
rect.nonselection_glyph = None
self.root.xaxis.minor_tick_line_alpha = 0
self.root.yaxis.visible = False
self.root.ygrid.visible = False
# fig.xaxis[0].formatter = NumeralTickFormatter(format='0.0s')
self.root.x_range.start = 0
tap = TapTool(callback=OpenURL(url="./info/worker/@escaped_worker.html"))
hover = HoverTool()
hover.tooltips = "@worker : @occupancy s."
hover.point_policy = "follow_mouse"
self.root.add_tools(hover, tap)
@without_property_validation
@log_errors
def update(self):
workers = self.scheduler.workers.values()
y = list(range(len(workers)))
occupancy = [ws.occupancy for ws in workers]
ms = [occ * 1000 for occ in occupancy]
x = [occ / 500 for occ in occupancy]
total = sum(occupancy)
color = []
for ws in workers:
if ws in self.scheduler.idle:
color.append("red")
elif ws in self.scheduler.saturated:
color.append("green")
else:
color.append("blue")
if total:
self.root.title.text = (
f"Occupancy -- total time: {format_time(total)} "
f"wall time: {format_time(total / self.scheduler.total_nthreads)}"
)
else:
self.root.title.text = "Occupancy"
if occupancy:
result = {
"occupancy": occupancy,
"worker": [ws.address for ws in workers],
"ms": ms,
"color": color,
"escaped_worker": [escape.url_escape(ws.address) for ws in workers],
"x": x,
"y": y,
}
update(self.source, result)
class ProcessingHistogram(DashboardComponent):
"""How many tasks are on each worker"""
@log_errors
def __init__(self, scheduler, **kwargs):
self.last = 0
self.scheduler = scheduler
self.source = ColumnDataSource(
{"left": [1, 2], "right": [10, 10], "top": [0, 0]}
)
self.root = figure(
title="Tasks Processing (count)",
id="bk-nprocessing-histogram-plot",
name="processing",
y_axis_label="frequency",
tools="",
**kwargs,
)
self.root.xaxis.minor_tick_line_alpha = 0
self.root.ygrid.visible = False
self.root.toolbar_location = None
self.root.quad(
source=self.source,
left="left",
right="right",
bottom=0,
top="top",
color="deepskyblue",
fill_alpha=0.5,
)
@without_property_validation
def update(self):
L = [len(ws.processing) for ws in self.scheduler.workers.values()]
counts, x = np.histogram(L, bins=40)
self.source.data.update({"left": x[:-1], "right": x[1:], "top": counts})
class MemoryColor:
"""Change the color of the memory bars from blue to orange when process memory goes
above the ``target`` threshold and to red when the worker pauses.
Workers in ``closing_gracefully`` state will also be orange.
If ``target`` is disabled, change to orange on ``spill`` instead.
If spilling is completely disabled, never turn orange.
If pausing is disabled, change to red when passing the ``terminate`` threshold
instead. If both pause and terminate are disabled, turn red when passing
``memory_limit``.
Note
----
A worker will start spilling when managed memory alone passes the target threshold.
However, here we're switching to orange when the process memory goes beyond target,
which is usually earlier.
This is deliberate for the sake of simplicity and also because, when the process
memory passes the spill threshold, it will keep spilling until it falls below the
target threshold - so it's not completely wrong. Again, we don't want to track
the hysteresis cycle of the spill system here for the sake of simplicity.
In short, orange should be treated as "the worker *may* be spilling".
"""
orange: float
red: float
def __init__(self):
target = dask.config.get("distributed.worker.memory.target")
spill = dask.config.get("distributed.worker.memory.spill")
terminate = dask.config.get("distributed.worker.memory.terminate")
# These values can be False. It's also common to configure them to impossibly
# high values to achieve the same effect.
self.orange = min(target or math.inf, spill or math.inf)
self.red = min(terminate or math.inf, 1.0)
def _memory_color(self, current: int, limit: int, status: Status) -> str:
if status != Status.running:
return "red"
if not limit:
return "blue"
if current >= limit * self.red:
return "red"
if current >= limit * self.orange:
return "orange"
return "blue"
class ClusterMemory(DashboardComponent, MemoryColor):
"""Total memory usage on the cluster"""
@log_errors
def __init__(self, scheduler, width=600, **kwargs):
DashboardComponent.__init__(self)
MemoryColor.__init__(self)
self.scheduler = scheduler
self.source = ColumnDataSource(
{
"width": [0] * 4,
"x": [0] * 4,
"y": [0] * 4,
"color": ["blue", "blue", "blue", "grey"],
"alpha": [1, 0.7, 0.4, 1],
"proc_memory": [0] * 4,
"managed": [0] * 4,
"unmanaged_old": [0] * 4,
"unmanaged_recent": [0] * 4,
"spilled": [0] * 4,
}
)
self.root = figure(
title="Bytes stored on cluster",
tools="",
id="bk-cluster-memory-plot",
width=int(width / 2),
name="cluster_memory",
min_border_bottom=50,
**kwargs,
)
rect = self.root.rect(
source=self.source,
x="x",
y="y",
width="width",
height=0.9,
color="color",
alpha="alpha",
)
rect.nonselection_glyph = None
self.root.axis[0].ticker = BasicTicker(**TICKS_1024)
self.root.xaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.root.xaxis.major_label_orientation = XLABEL_ORIENTATION
self.root.xaxis.minor_tick_line_alpha = 0
self.root.x_range = Range1d(start=0)
self.root.yaxis.visible = False
self.root.ygrid.visible = False
self.root.toolbar_location = None
self.root.yaxis.visible = False
hover = HoverTool(
point_policy="follow_mouse",
tooltips="""
<div>
<span style="font-size: 12px; font-weight: bold;">Process memory (RSS):</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@proc_memory{0.00 b}</span>
</div>
<div style="margin-left: 1em;">
<span style="font-size: 12px; font-weight: bold;">Managed:</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@managed{0.00 b}</span>
</div>
<div style="margin-left: 1em;">
<span style="font-size: 12px; font-weight: bold;">Unmanaged (old):</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_old{0.00 b}</span>
</div>
<div style="margin-left: 1em;">
<span style="font-size: 12px; font-weight: bold;">Unmanaged (recent):</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_recent{0.00 b}</span>
</div>
<div>
<span style="font-size: 12px; font-weight: bold;">Spilled to disk:</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@spilled{0.00 b}</span>
</div>
""",
)
self.root.add_tools(hover)
def _cluster_memory_color(self) -> str:
colors = {
self._memory_color(
current=ws.memory.process,
limit=getattr(ws, "memory_limit", 0),
status=ws.status,
)
for ws in self.scheduler.workers.values()
}
assert colors.issubset({"red", "orange", "blue"})
if "red" in colors:
return "red"
elif "orange" in colors:
return "orange"
else:
return "blue"
@without_property_validation
@log_errors
def update(self):
limit = sum(ws.memory_limit for ws in self.scheduler.workers.values())
meminfo = self.scheduler.memory
color = self._cluster_memory_color()
width = [
meminfo.managed_in_memory,
meminfo.unmanaged_old,
meminfo.unmanaged_recent,
meminfo.managed_spilled,
]
result = {
"width": width,
"x": [sum(width[:i]) + w / 2 for i, w in enumerate(width)],
"color": [color, color, color, "grey"],
"proc_memory": [meminfo.process] * 4,
"managed": [meminfo.managed_in_memory] * 4,
"unmanaged_old": [meminfo.unmanaged_old] * 4,
"unmanaged_recent": [meminfo.unmanaged_recent] * 4,
"spilled": [meminfo.managed_spilled] * 4,
}
x_end = max(limit, meminfo.process + meminfo.managed_spilled)
self.root.x_range.end = x_end
title = f"Bytes stored: {format_bytes(meminfo.process)}"
if meminfo.managed_spilled:
title += f" + {format_bytes(meminfo.managed_spilled)} spilled to disk"
self.root.title.text = title
update(self.source, result)
class WorkersMemory(DashboardComponent, MemoryColor):
"""Memory usage for single workers"""
@log_errors
def __init__(self, scheduler, width=600, **kwargs):
DashboardComponent.__init__(self)
MemoryColor.__init__(self)
self.scheduler = scheduler
self.source = ColumnDataSource(
{
"width": [],
"x": [],
"y": [],
"color": [],
"alpha": [],
"worker": [],
"escaped_worker": [],
"proc_memory": [],
"managed": [],
"unmanaged_old": [],
"unmanaged_recent": [],
"spilled": [],
}
)
self.root = figure(
title="Bytes stored per worker",
tools="",
id="bk-workers-memory-plot",
width=int(width / 2),
name="workers_memory",
min_border_bottom=50,
**kwargs,
)
rect = self.root.rect(
source=self.source,
x="x",
y="y",
width="width",
height=0.9,
color="color",
fill_alpha="alpha",
line_width=0,
)
rect.nonselection_glyph = None
self.root.axis[0].ticker = BasicTicker(**TICKS_1024)
self.root.xaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.root.xaxis.major_label_orientation = XLABEL_ORIENTATION
self.root.xaxis.minor_tick_line_alpha = 0
self.root.x_range = Range1d(start=0)
self.root.yaxis.visible = False
self.root.ygrid.visible = False
self.root.toolbar_location = None
tap = TapTool(callback=OpenURL(url="./info/worker/@escaped_worker.html"))
self.root.add_tools(tap)
hover = HoverTool(
point_policy="follow_mouse",
tooltips="""
<div>
<span style="font-size: 12px; font-weight: bold;">Worker:</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@worker</span>
</div>
<div>
<span style="font-size: 12px; font-weight: bold;">Process memory (RSS):</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@proc_memory{0.00 b}</span>
</div>
<div style="margin-left: 1em;">
<span style="font-size: 12px; font-weight: bold;">Managed:</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@managed{0.00 b}</span>
</div>
<div style="margin-left: 1em;">
<span style="font-size: 12px; font-weight: bold;">Unmanaged (old):</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_old{0.00 b}</span>
</div>
<div style="margin-left: 1em;">
<span style="font-size: 12px; font-weight: bold;">Unmanaged (recent):</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@unmanaged_recent{0.00 b}</span>
</div>
<div>
<span style="font-size: 12px; font-weight: bold;">Spilled to disk:</span>
<span style="font-size: 10px; font-family: Monaco, monospace;">@spilled{0.00 b}</span>
</div>
""",
)
self.root.add_tools(hover)
@without_property_validation
@log_errors
def update(self):
def quadlist(i: Iterable[T]) -> list[T]:
out = []
for ii in i:
out += [ii, ii, ii, ii]
return out
workers = self.scheduler.workers.values()
width = []
x = []
color = []
max_limit = 0
procmemory = []
managed = []
spilled = []
unmanaged_old = []
unmanaged_recent = []
for ws in workers:
meminfo = ws.memory
limit = getattr(ws, "memory_limit", 0)
max_limit = max(max_limit, limit, meminfo.process + meminfo.managed_spilled)
color_i = self._memory_color(meminfo.process, limit, ws.status)
width += [
meminfo.managed_in_memory,
meminfo.unmanaged_old,
meminfo.unmanaged_recent,
meminfo.managed_spilled,
]
x += [sum(width[-4:i]) + width[i] / 2 for i in range(-4, 0)]
color += [color_i, color_i, color_i, "grey"]
# memory info
procmemory.append(meminfo.process)
managed.append(meminfo.managed_in_memory)
unmanaged_old.append(meminfo.unmanaged_old)
unmanaged_recent.append(meminfo.unmanaged_recent)
spilled.append(meminfo.managed_spilled)
result = {
"width": width,
"x": x,
"color": color,
"alpha": [1, 0.7, 0.4, 1] * len(workers),
"worker": quadlist(ws.address for ws in workers),
"escaped_worker": quadlist(escape.url_escape(ws.address) for ws in workers),
"y": quadlist(range(len(workers))),
"proc_memory": quadlist(procmemory),
"managed": quadlist(managed),
"unmanaged_old": quadlist(unmanaged_old),
"unmanaged_recent": quadlist(unmanaged_recent),
"spilled": quadlist(spilled),
}
# Remove rectangles with width=0
result = {k: [vi for vi, w in zip(v, width) if w] for k, v in result.items()}
self.root.x_range.end = max_limit
update(self.source, result)
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.
"""
@log_errors
def __init__(self, scheduler, **kwargs):
self.last = 0
self.scheduler = scheduler
self.source = ColumnDataSource(
{"left": [1, 2], "right": [10, 10], "top": [0, 0]}
)
self.root = figure(
title="Bytes stored per worker",
name="workers_memory",
id="bk-workers-memory-histogram-plot",
y_axis_label="frequency",
tools="",
**kwargs,
)
self.root.xaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.root.xaxis.ticker = AdaptiveTicker(**TICKS_1024)
self.root.xaxis.major_label_orientation = XLABEL_ORIENTATION
self.root.xaxis.minor_tick_line_alpha = 0
self.root.ygrid.visible = False
self.root.toolbar_location = None
self.root.quad(
source=self.source,
left="left",
right="right",
bottom=0,
top="top",
color="deepskyblue",
fill_alpha=0.5,
)
@without_property_validation
def update(self):
nbytes = np.asarray(
[ws.metrics["memory"] for ws in self.scheduler.workers.values()]
)
counts, x = np.histogram(nbytes, bins=40)
d = {"left": x[:-1], "right": x[1:], "top": counts}
update(self.source, d)
class WorkersTransferBytes(DashboardComponent):
"""Size of open data transfers from/to other workers per worker"""
@log_errors
def __init__(self, scheduler, width=600, **kwargs):
self.scheduler = scheduler
self.source = ColumnDataSource(
{
"escaped_worker": [],
"transfer_incoming_bytes": [],
"transfer_outgoing_bytes": [],
"worker": [],
"y_incoming": [],
"y_outgoing": [],
}
)
self.root = figure(
title=f"Bytes transferring: {format_bytes(0)}",
tools="",
id="bk-workers-transfer-bytes-plot",
width=int(width / 2),
name="workers_transfer_bytes",
min_border_bottom=50,
**kwargs,
)
# transfer_incoming_bytes
self.root.hbar(
name="transfer_incoming_bytes",
y="y_incoming",
right="transfer_incoming_bytes",
line_color=None,
left=0,
height=0.5,
fill_color="red",
source=self.source,
)
# transfer_outgoing_bytes
self.root.hbar(
name="transfer_outgoing_bytes",
y="y_outgoing",
right="transfer_outgoing_bytes",
line_color=None,
left=0,
height=0.5,
fill_color="blue",
source=self.source,
)
self.root.axis[0].ticker = BasicTicker(**TICKS_1024)
self.root.xaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.root.xaxis.major_label_orientation = XLABEL_ORIENTATION
self.root.xaxis.minor_tick_line_alpha = 0
self.root.x_range = Range1d(start=0)
self.root.yaxis.visible = False
self.root.ygrid.visible = False
self.root.toolbar_location = None
tap = TapTool(callback=OpenURL(url="./info/worker/@escaped_worker.html"))
hover = HoverTool(
tooltips=[
("Worker", "@worker"),
("Incoming", "@transfer_incoming_bytes{0.00 b}"),
("Outgoing", "@transfer_outgoing_bytes{0.00 b}"),
],
point_policy="follow_mouse",
)
self.root.add_tools(hover, tap)
@without_property_validation
@log_errors
def update(self):
wss = self.scheduler.workers.values()
h = 0.1
y_incoming = [i + 0.75 + i * h for i in range(len(wss))]
y_outgoing = [i + 0.25 + i * h for i in range(len(wss))]
transfer_incoming_bytes = [
ws.metrics["transfer"]["incoming_bytes"] for ws in wss
]
transfer_outgoing_bytes = [
ws.metrics["transfer"]["outgoing_bytes"] for ws in wss
]
workers = [ws.address for ws in wss]
escaped_workers = [escape.url_escape(worker) for worker in workers]
if wss:
x_limit = max(
max(transfer_incoming_bytes),
max(transfer_outgoing_bytes),
max(ws.memory_limit for ws in wss),
)
else:
x_limit = 0
self.root.x_range.end = x_limit
result = {
"escaped_worker": escaped_workers,
"transfer_incoming_bytes": transfer_incoming_bytes,
"transfer_outgoing_bytes": transfer_outgoing_bytes,
"worker": workers,
"y_incoming": y_incoming,
"y_outgoing": y_outgoing,
}
self.root.title.text = (
f"Bytes transferring: {format_bytes(sum(transfer_incoming_bytes))}"
)
update(self.source, result)
class Hardware(DashboardComponent):
"""Occupancy (in time) per worker"""
@log_errors
def __init__(self, scheduler, **kwargs):
self.scheduler = scheduler
# Disk
self.disk_source = ColumnDataSource(
{
"size": [],
"bandwidth": [],
}
)
self.disk_figure = figure(
title="Disk Bandwidth -- Computing ...",
tools="",
toolbar_location="above",
x_range=FactorRange(factors=[]),
**kwargs,
)
self.disk_figure.vbar(
x="size", top="bandwidth", width=0.9, source=self.disk_source
)
hover = HoverTool(
mode="vline", tooltips=[("Bandwidth", "@bandwidth{0.00 b}/s")]
)
self.disk_figure.add_tools(hover)
self.disk_figure.yaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.disk_figure.xgrid.visible = False
# Memory
self.memory_source = ColumnDataSource(
{
"size": [],
"bandwidth": [],
}
)
self.memory_figure = figure(
title="Memory Bandwidth -- Computing ...",
tools="",
toolbar_location="above",
x_range=FactorRange(factors=[]),
**kwargs,
)
self.memory_figure.vbar(
x="size", top="bandwidth", width=0.9, source=self.memory_source
)
hover = HoverTool(
mode="vline", tooltips=[("Bandwidth", "@bandwidth{0.00 b}/s")]
)
self.memory_figure.add_tools(hover)
self.memory_figure.yaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.memory_figure.xgrid.visible = False
# Network
self.network_source = ColumnDataSource(
{
"size": [],
"bandwidth": [],
}
)
self.network_figure = figure(
title="Network Bandwidth -- Computing ...",
tools="",
toolbar_location="above",
x_range=FactorRange(factors=[]),
**kwargs,
)
self.network_figure.vbar(
x="size", top="bandwidth", width=0.9, source=self.network_source
)
hover = HoverTool(
mode="vline", tooltips=[("Bandwidth", "@bandwidth{0.00 b}/s")]
)
self.network_figure.add_tools(hover)
self.network_figure.yaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.network_figure.xgrid.visible = False
self.root = row(
self.memory_figure,
self.disk_figure,
self.network_figure,
)
self.memory_data = {
"size": [],
"bandwidth": [],
}
self.disk_data = {
"size": [],
"bandwidth": [],
}
self.network_data = {
"size": [],
"bandwidth": [],
}
async def f():
result = await self.scheduler.benchmark_hardware()
for size in sorted(result["disk"], key=parse_bytes):
bandwidth = result["disk"][size]
self.disk_data["size"].append(size)
self.disk_data["bandwidth"].append(bandwidth)
for size in sorted(result["memory"], key=parse_bytes):
bandwidth = result["memory"][size]
self.memory_data["size"].append(size)
self.memory_data["bandwidth"].append(bandwidth)
for size in sorted(result["network"], key=parse_bytes):
bandwidth = result["network"][size]
self.network_data["size"].append(size)
self.network_data["bandwidth"].append(bandwidth)
self.scheduler.loop.add_callback(f)
def update(self):
if (
not self.disk_data["size"]
or self.disk_figure.title.text == "Disk Bandwidth"
):
return
self.network_figure.x_range.factors = self.network_data["size"]
self.disk_figure.x_range.factors = self.disk_data["size"]
self.memory_figure.x_range.factors = self.memory_data["size"]
update(self.disk_source, self.disk_data)
update(self.memory_source, self.memory_data)
update(self.network_source, self.network_data)
self.memory_figure.title.text = "Memory Bandwidth"
self.disk_figure.title.text = "Disk Bandwidth"
self.network_figure.title.text = "Network Bandwidth"
class BandwidthTypes(DashboardComponent):
"""Bar chart showing bandwidth per type"""
@log_errors
def __init__(self, scheduler, **kwargs):
self.last = 0
self.scheduler = scheduler
self.source = ColumnDataSource(
{
"bandwidth": [1, 2],
"bandwidth-half": [0.5, 1],
"type": ["a", "b"],
"bandwidth_text": ["1", "2"],
}
)
self.root = figure(
title="Bandwidth by Type",
tools="",
id="bk-bandwidth-type-plot",
name="bandwidth_type_histogram",
y_range=["a", "b"],
**kwargs,
)
self.root.xaxis.major_label_orientation = -0.5
rect = self.root.rect(
source=self.source,
x="bandwidth-half",
y="type",
width="bandwidth",
height=0.9,
color="blue",
)
self.root.x_range.start = 0
self.root.xaxis[0].formatter = NumeralTickFormatter(format="0.0 b")
self.root.xaxis.ticker = AdaptiveTicker(**TICKS_1024)
rect.nonselection_glyph = None
self.root.xaxis.minor_tick_line_alpha = 0
self.root.ygrid.visible = False
self.root.toolbar_location = None
hover = HoverTool()
hover.tooltips = "@type: @bandwidth_text / s"
hover.point_policy = "follow_mouse"
self.root.add_tools(hover)
@without_property_validation
@log_errors
def update(self):
bw = self.scheduler.bandwidth_types
self.root.y_range.factors = list(sorted(bw))
result = {
"bandwidth": list(bw.values()),
"bandwidth-half": [b / 2 for b in bw.values()],
"type": list(bw.keys()),
"bandwidth_text": [format_bytes(x) for x in bw.values()],
}
self.root.title.text = "Bandwidth: " + format_bytes(self.scheduler.bandwidth)
update(self.source, result)
class BandwidthWorkers(DashboardComponent):
"""How many tasks are on each worker"""
@log_errors
def __init__(self, scheduler, **kwargs):
self.last = 0
self.scheduler = scheduler
self.source = ColumnDataSource(
{
"bandwidth": [1, 2],
"source": ["a", "b"],
"destination": ["a", "b"],
"bandwidth_text": ["1", "2"],
}
)
values = [hex(x)[2:] for x in range(64, 256)][::-1]
mapper = linear_cmap(
field_name="bandwidth",
palette=["#" + x + x + "FF" for x in values],
low=0,
high=1,
)
self.root = figure(
title="Bandwidth by Worker",
tools="",
id="bk-bandwidth-worker-plot",
name="bandwidth_worker_heatmap",
x_range=["a", "b"],
y_range=["a", "b"],
**kwargs,
)
self.root.xaxis.major_label_orientation = XLABEL_ORIENTATION
self.root.rect(
source=self.source,
x="source",
y="destination",
color=mapper,
height=1,
width=1,
)
self.color_map = mapper["transform"]
color_bar = ColorBar(
color_mapper=self.color_map,
label_standoff=12,
border_line_color=None,
location=(0, 0),
)
color_bar.formatter = NumeralTickFormatter(format="0.0 b")
color_bar.ticker = AdaptiveTicker(**TICKS_1024)