當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python dask.distributed.SSHCluster用法及代碼示例

用法:

dask.distributed.SSHCluster(hosts: list[str] | None = None, connect_options: dict | list[dict] = {}, worker_options: dict = {}, scheduler_options: dict = {}, worker_module: str = 'deprecated', worker_class: str = 'distributed.Nanny', remote_python: str | list[str] | None = None, **kwargs)

使用 SSH 部署 Dask 集群

SSHCluster 函數在您提供的一組機器地址上為您部署 Dask Scheduler 和 Workers。第一個地址將用於調度程序,其餘的將用於工作程序(如果您希望調度程序和工作程序 co-habitate 一台機器,請隨意重複第一個主機名。)

您可以通過傳遞 scheduler_optionsworker_options 字典關鍵字來配置調度程序和工作程序。有關可用選項的詳細信息,請參閱dask.distributed.Schedulerdask.distributed.Worker 類,但默認值應該適用於大多數情況。

您可以使用 connect_options 關鍵字配置您對 SSH 本身的使用,該關鍵字將值傳遞給 asyncssh.connect 函數。有關這些的更多信息,請參閱 asyncsshhttps://asyncssh.readthedocs.io 的文檔。

參數

hosts列表[str]

啟動集群的主機名或地址列表。第一個將用於調度程序,其餘用於工作人員。

connect_optionsdict或dict列表,可選

要傳遞給 asyncssh.connect() 的關鍵字。這可能包括諸如 port , username , passwordknown_hosts 之類的東西。有關完整信息,請參閱asyncssh.connect()asyncssh.SSHClientConnectionOptions 的文檔。如果是列表,它的長度必須與 hosts 相同。

worker_options字典,可選

傳遞給工人的關鍵字。

scheduler_options字典,可選

傳遞給調度程序的關鍵字。

worker_class: str

用於創建工作人員的 python 類。

remote_pythonstr 或 str 列表,可選

遠程節點上的 Python 路徑。

例子

創建一個包含一個工作人員的集群:

>>> from dask.distributed import Client, SSHCluster
>>> cluster = SSHCluster(["localhost", "localhost"])
>>> client = Client(cluster)

創建一個包含三個工作人員的集群,每個工作人員有兩個線程,並在端口 8797 上托管儀表板:

>>> from dask.distributed import Client, SSHCluster
>>> cluster = SSHCluster(
...     ["localhost", "localhost", "localhost", "localhost"],
...     connect_options={"known_hosts": None},
...     worker_options={"nthreads": 2},
...     scheduler_options={"port": 0, "dashboard_address": ":8797"}
... )
>>> client = Client(cluster)

在每台主機上創建一個包含兩個工作人員的集群:

>>> from dask.distributed import Client, SSHCluster
>>> cluster = SSHCluster(
...     ["localhost", "localhost", "localhost", "localhost"],
...     connect_options={"known_hosts": None},
...     worker_options={"nthreads": 2, "n_workers": 2},
...     scheduler_options={"port": 0, "dashboard_address": ":8797"}
... )
>>> client = Client(cluster)

使用不同工作類的示例,特別是來自 dask-cuda 項目的 CUDAWorker

>>> from dask.distributed import Client, SSHCluster
>>> cluster = SSHCluster(
...     ["localhost", "hostwithgpus", "anothergpuhost"],
...     connect_options={"known_hosts": None},
...     scheduler_options={"port": 0, "dashboard_address": ":8797"},
...     worker_class="dask_cuda.CUDAWorker")
>>> client = Client(cluster)

相關用法


注:本文由純淨天空篩選整理自dask.org大神的英文原創作品 dask.distributed.SSHCluster。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。