在 dask 分布式中从线程池分离任务
Seceding tasks from thread pools in dask distributed
我一直在阅读有关从工作人员 运行ning 任务生成新进程的文档。我从 here:
看到这个
However, each running task takes up a single thread, and so if you launch many tasks that launch other tasks then it is possible to deadlock the system if you are not careful. You can call the secede function from within a task to have it remove itself from the dedicated thread pool into an administrative thread that does not take up a slot within the Dask worker
移至管理线程是什么意思?是否所有插槽都具有相同的优先级或类似的优先级?管理线程确实有优先权?
作为一个具体的例子,这是我想尝试的:
from dask.distributed import get_client, secede
def compute_square(x):
# Get locally created client
client = get_client()
secede() # or not?
if x > 5:
client.submit(lambda x : x**2, x)
其中 compute_square
和 lambda
函数可能会 运行 很多次,并且是一个计算量更大的函数,值得提交作业的 1 毫秒开销。
在这种情况下我应该使用 secede
吗?
What does it mean to move to an administrative thread?
Dask worker 为 运行ning 任务维护一个固定大小的线程池。当您调用 secede
时,您的计算将离开此线程池并为其他任务打开另一个槽 运行。您的任务线程仍然存在,但只是一个普通线程。术语 "administrative thread" 除了 "a thread not in the thread pool".
之外没有任何特别的含义
Are all slots given the same priority or something similar?
一旦任务 运行ning 就没有它们之间的优先级。它们都 运行 在没有优先级的正常 Python 线程中。
And the administrative thread does have priority?
没有
Should I be using secede in this case?
如果
你应该打电话给secede
- 您可能会调用足够多的任务,这些任务都在等待其他任务,以至于没有任务可以完成,因为您的线程池的所有线程都在等待其他插槽打开。
- 您不打算在该任务中做更多的工作
如果
你不应该打电话给secede
- 您打算在调用
secede
后在任务中做更多的计算工作。这仍然没问题,但有点不礼貌,因为 Dask 会在没有任何限制的情况下轻松启动其中的几个任务。
我一直在阅读有关从工作人员 运行ning 任务生成新进程的文档。我从 here:
看到这个However, each running task takes up a single thread, and so if you launch many tasks that launch other tasks then it is possible to deadlock the system if you are not careful. You can call the secede function from within a task to have it remove itself from the dedicated thread pool into an administrative thread that does not take up a slot within the Dask worker
移至管理线程是什么意思?是否所有插槽都具有相同的优先级或类似的优先级?管理线程确实有优先权?
作为一个具体的例子,这是我想尝试的:
from dask.distributed import get_client, secede
def compute_square(x):
# Get locally created client
client = get_client()
secede() # or not?
if x > 5:
client.submit(lambda x : x**2, x)
其中 compute_square
和 lambda
函数可能会 运行 很多次,并且是一个计算量更大的函数,值得提交作业的 1 毫秒开销。
在这种情况下我应该使用 secede
吗?
What does it mean to move to an administrative thread?
Dask worker 为 运行ning 任务维护一个固定大小的线程池。当您调用 secede
时,您的计算将离开此线程池并为其他任务打开另一个槽 运行。您的任务线程仍然存在,但只是一个普通线程。术语 "administrative thread" 除了 "a thread not in the thread pool".
Are all slots given the same priority or something similar?
一旦任务 运行ning 就没有它们之间的优先级。它们都 运行 在没有优先级的正常 Python 线程中。
And the administrative thread does have priority?
没有
Should I be using secede in this case?
如果
你应该打电话给secede
- 您可能会调用足够多的任务,这些任务都在等待其他任务,以至于没有任务可以完成,因为您的线程池的所有线程都在等待其他插槽打开。
- 您不打算在该任务中做更多的工作
如果
你不应该打电话给secede
- 您打算在调用
secede
后在任务中做更多的计算工作。这仍然没问题,但有点不礼貌,因为 Dask 会在没有任何限制的情况下轻松启动其中的几个任务。