仪表盘诊断

并行代码的性能分析可能具有挑战性,但 Dask 分布式调度器提供的交互式仪表盘通过对 Dask 计算进行实时监控,使此过程变得更容易。该仪表盘使用 Bokeh 构建,并在调度器创建时自动启动,返回一个指向仪表盘的链接。

在本地,这发生在您创建 Client 并连接调度器时

from dask.distributed import Client
client = Client()  # start distributed scheduler locally.

在 Jupyter Notebook 或 JupyterLab 会话中显示 client 对象将显示仪表盘地址

Client html repr displaying the dashboard link in a JupyterLab session.

您还可以从 client.dashboard_link 查询地址(对于旧版本的 distributed,则是 client.scheduler_info()['services'])。

默认情况下,当您在本地机器上启动调度器时,仪表盘将提供服务于 https://:8787/status。您可以在浏览器中输入此地址来访问仪表盘,但如果端口 8787 被占用,可能会被重定向到其他地址。您还可以使用 dashboard_address 参数配置地址(参见 LocalCluster)。

有许多可用的诊断图。在本指南中,您将了解仪表盘入口点上显示的一些最常用的图表。

Main dashboard with five panes arranged into two columns. In the left column there are three bar charts. The top two show total bytes stored and bytes per worker. The bottom has three tabs to toggle between task processing, CPU utilization, and occupancy. In the right column, there are two bar charts with corresponding colors showing task activity over time, referred to as task stream and progress.

存储字节数和每工作节点的字节数

这两个图表显示了集群上的总体内存使用情况(存储字节数)摘要,以及每个工作节点上的独立使用情况(每工作节点的字节数)。这些图表上的颜色表示以下含义。

内存低于目标阈值(默认为可用内存的 60%)
内存接近溢出到磁盘的阈值(默认为可用内存的 70%)
当工作节点(或至少一个工作节点)暂停(默认为可用内存的 80%)或正在退役时
内存溢出到磁盘
Two bar charts on memory usage. The top chart shows the total cluster memory in a single bar with mostly under target memory - changing colors according to memory usage, (blue - under target, orange - Memory is about to be spilled, red - paused or retiring, and a small part of spilled to disk in grey. The bottom chart displays the memory usage per worker, with a separate bar for each of the four workers. The four bars can be seen in various colours as in blue when under target, orange as their worker's memory are close to the spilling to disk target, with the second and fourth worker standing out with a portion in grey that correspond to the amount spilled to disk, also fourth worker in red is paused or about to retire.

这些图表上不同的透明度级别与内存类型(托管内存、非托管内存和最近的非托管内存)有关,您可以在工作节点内存管理文档中找到它们的详细解释。

任务处理/CPU 利用率/占用率/数据传输

任务处理

图中的“处理中”选项卡显示分配给每个工作节点的任务数量。并非所有这些任务都在当前执行:一个工作节点一次只执行与其拥有的线程数量相同的任务。分配给工作节点的任何额外任务将等待运行,这取决于它们的优先级以及它们的依赖项是否位于工作节点的内存中。

调度器会尽量确保工作节点处理的任务数量大致相同。如果其中一个条完全是白色的,则意味着该工作节点没有任务,正在等待任务。这通常发生在计算即将完成时(无需担心),但也可能意味着任务在工作节点间的分布未得到优化。

该图表中可能出现三种不同的颜色

正在处理任务。
饱和:有足够的工作使其保持忙碌。
空闲:没有足够的工作使其保持忙碌。
Task Processing bar chart, showing a relatively even number of tasks on each worker.

在仪表盘的此图中,我们还有两个额外的选项卡,包含以下信息:

CPU 利用率

“CPU”选项卡显示通过 psutil 指标报告的每工作节点的 CPU 使用情况。

占用率

“占用率”选项卡显示了每工作节点的时间占用情况。工作节点的总占用率是 Dask 预期的运行所有任务并从其他工作节点传输其任何依赖项所需的时间总量,前提是执行和传输是按顺序进行的。例如,如果一个工作节点的占用率为 10 秒,并且它有 2 个线程,您可以预期该工作节点大约需要 5 秒的实际运行时间来完成所有任务。

数据传输

“数据传输”选项卡显示每个工作节点与其他工作节点之间正在进行的数据传输大小。

任务流

任务流是一个视图,显示了每个工作节点每个线程上运行的任务。每一行代表一个线程,每个矩形代表一个独立任务。每个矩形的颜色对应于正在执行任务的任务前缀 (task-prefix),并与进度图的颜色相匹配。这意味着属于 inc 任务前缀的所有独立任务,例如,将具有相同的颜色(该颜色从 viridis 颜色图中随机选择)。

注意,当一个新的工作节点加入时,即使它是替换最近离开的工作节点,它也会获得新的一行。因此,任务流上显示的行数可能暂时多于集群当前线程的总数,因为旧工作节点和新工作节点的历史记录都会显示。

有些颜色保留用于特定类型的操作

工作节点之间的数据传输。
从磁盘读取或写入磁盘。
序列化/反序列化数据。
出错的任务。

在某些场景下,仪表盘上每个矩形之间会出现白色空间。在此期间,工作节点线程处于空闲状态。白色空间过多表明资源利用不充分。此外,许多长红色条(传输)可能表明存在性能问题,原因可能包括分块大小 (chunksizes) 过大、图过于复杂,甚至是糟糕的调度选择。

The stacked bar chart, with one bar per worker-thread, has different shades of blue and green for different tasks, with occasional, very narrow red bars overlapping them.

一个健康的任务流示例,几乎没有白色空间。传输(红色)很快,并且与计算重叠。

The stacked bar chart, with one bar per worker-thread, is mostly empty (white). Each row only has a few occasional spurts of activity. There are also red and orange bars, some of which are long and don't overlap with the other colors.

一个不健康的任务流示例,有大量的白色空间。工作节点大部分时间都处于空闲状态。此外,还有一些长的传输(红色)没有与计算重叠。我们还看到内存溢出到磁盘(橙色)。

进度

进度条图显示了每个独立任务前缀的进度。每个条的颜色与任务流中同一任务前缀的单个任务的颜色相匹配。每个水平条从左到右包含四个不同的组成部分:

  • 已完成、不再需要且已从内存中释放的任务。
  • 已完成并存储在内存中的任务。
  • 准备运行的任务。
  • 排队中的任务。它们已准备好运行,但尚未分配给工作节点,以便高优先级的任务可以先运行。
  • 由于限制资源不足而没有工作节点可运行的任务。
Progress bar chart with one bar for each task-prefix matching with the names "add", "double", "inc", and "sum". The "double", "inc" and "add" bars have a progress of approximately one third of the total tasks, displayed in their individual color with different transparency levels. The "double" and "inc" bars have a striped grey background, and the "sum" bar is empty.

Dask JupyterLab 扩展

JupyterLab Dask 扩展允许您将 Dask 的仪表盘图表直接嵌入到 JupyterLab 面板中。

安装 JupyterLab Dask 扩展后,您可以选择任何可用的独立图表并将其集成到您的 JupyterLab 会话中作为面板。例如,在下图中,我们选择了“任务流”、“进度”、“工作节点内存”和“图”图表。

Dask JupyterLab extension showing an arrangement of four panes selected from a display of plot options. The panes displayed are the Task stream, Bytes per worker, Progress and the Task Graph.