诊断 (分布式)

Dask 分布式调度器 提供两种形式的实时反馈

  1. 一个交互式 Dashboard,包含许多带有实时信息的图表和表格

  2. 一个适用于控制台或 Notebook 交互式使用的进度条

Dashboard

有关 Dask Dashboard 的信息,请参阅 Dashboard 诊断

捕获诊断信息

get_task_stream([client, plot, filename])

在上下文块内收集任务流

Client.profile([key, start, stop, workers, ...])

收集关于最近工作的统计分析信息

performance_report([filename, stacklevel, ...])

收集性能报告

您可以使用 get_task_streamClient.profile 函数捕获 Dashboard 呈现的一些信息,以便进行离线处理。这些函数会捕获每个任务和传输的开始和停止时间,以及统计分析器的结果。

with get_task_stream(plot='save', filename="task-stream.html") as ts:
    x.compute()

client.profile(filename="dask-profile.html")

history = ts.data

此外,Dask 可以使用 performance_report 上下文管理器一次性保存多个诊断 Dashboard,包括任务流、worker 分析、带宽等。

from dask.distributed import performance_report

with performance_report(filename="dask-report.html"):
    ## some dask computation

以下视频更详细地演示了 performance_report 上下文管理器

进度条

progress(*futures[, notebook, multi, ...])

跟踪 Future 对象的进度

dask.distributed 的进度条与用于 本地诊断ProgressBar 不同。progress 函数接受一个在后台执行的 Dask 对象

# Progress bar on a single-machine scheduler
from dask.diagnostics import ProgressBar

with ProgressBar():
    x.compute()

# Progress bar with the distributed scheduler
from dask.distributed import Client, progress

client = Client()  # use dask.distributed by default

x = x.persist()  # start computation in the background
progress(x)      # watch progress

x.compute()      # convert to final result when done if desired

连接到 Dashboard

一些计算机网络可能会限制对特定端口的访问,或仅允许特定机器访问。如果您无法访问 Dashboard,您可能需要联系您的 IT 管理员。

下面是一些常见问题和解决方案

指定一个可访问的端口

一些集群限制了对外部可见的端口。这些端口可能包括 Web 界面的默认端口 8787。有几种方法可以解决这个问题

  1. 将端口 8787 对外开放。通常这需要联系您的集群管理员。

  2. dask-scheduler 命令上使用 --dashboard-address :8787 选项,使用一个公开可访问的其他端口。

  3. 使用更高级的技术,例如 端口转发

端口转发

如果您有 SSH 访问权限,那么访问被阻止端口的一种方法是通过 SSH 端口转发。一个典型的用例如下所示

local$ ssh -L 8000:localhost:8787 user@remote
remote$ dask-scheduler  # now, the web UI is visible at localhost:8000
remote$ # continue to set up dask if needed -- add workers, etc

然后就可以访问 localhost:8000 并查看 Dask Web UI。这种方法并非 Dask 分布式特有,而是可用于任何通过网络运行的服务,例如 Jupyter Notebook。例如,如果我们选择这样做,我们可以使用 ssh -L 8001:localhost:8888 user@remote 将端口 8888 (Jupyter 默认端口) 转发到端口 8001。

所需软件包

必须在调度器环境中安装 Bokeh 才能运行 Dashboard。如果未安装,Dashboard 页面会提示您安装。

根据您的配置,您可能还需要安装 jupyter-server-proxy 才能访问 Dashboard。

API

dask.distributed.progress(*futures, notebook=None, multi=True, complete=True, group_by='prefix', **kwargs)[source]

跟踪 Future 对象的进度

在 Notebook 和控制台中表现不同

  • Notebook: 立即返回,并在屏幕上留下一个 IPython 小部件

  • 控制台: 阻塞直到计算完成

参数
futuresFuture 对象

要跟踪的 Future 对象列表或键

notebookbool (可选)

是否在 Notebook 中运行 (默认为自动检测)

multibool (可选)

独立跟踪不同的函数 (默认为 True)

completebool (可选)

跟踪所有键 (True) 或仅跟踪尚未运行的键 (False) (默认为 True)

group_by可调用对象 | Literal[“spans”] | Literal[“prefix”]

使用 spans 而非任务键名对任务进行分组 (默认为 “prefix”)

注意

在 Notebook 中,progress 的输出必须是单元格中的最后一条语句。通常,这意味着在单元格末尾调用 progress

示例

>>> progress(futures)  
[########################################] | 100% Completed |  1.7s
dask.distributed.get_task_stream(client=None, plot=False, filename='task-stream.html')[source]

在上下文块内收集任务流

这提供了在此块激活期间运行的每个任务的诊断信息。

这必须用作上下文管理器。

参数
plot: boolean, str

如果为 True,则同时返回 Bokeh 图;如果 plot == ‘save’,则将图保存到文件

filename: str (可选)

如果设置了 plot='save',则保存到的文件名

另请参阅

Client.get_task_stream

此上下文管理器的函数版本

示例

>>> with get_task_stream() as ts:
...     x.compute()
>>> ts.data
[...]

获取 Bokeh 图,并可选择保存到文件

>>> with get_task_stream(plot='save', filename='task-stream.html') as ts:
...    x.compute()
>>> ts.figure
<Bokeh Figure>

要与他人共享此文件,您可能希望将其上传并在线提供。一种常见的方法是将其作为 Gist 上传,然后在 https://raw.githack.com 上提供。

$ python -m pip install gist
$ gist task-stream.html
https://gist.github.com/8a5b3c74b10b413f612bb5e250856ceb

然后,您可以导航到该网站,点击 task-stream.html 文件右侧的“Raw”按钮,然后将该 URL 提供给 https://raw.githack.com。此过程应提供一个可共享的链接,供其他人查看您的任务流图。