(黄昏)如何分配计算所需的昂贵资源?

时间:2018-10-03 18:31:18

标签: pandas dask python-3.7 dask-distributed

在使用相对昂贵的创建资源或对象进行计算的数据集中分布任务的最佳方法是什么。

# in pandas
df = pd.read_csv(...)
foo = Foo() # expensive initialization.
result = df.apply(lambda x: foo.do(x))

# in dask?
# is it possible to scatter the foo to the workers?
client.scatter(...

我计划将其与带有SGECluster的dask_jobqueue一起使用。

1 个答案:

答案 0 :(得分:1)

foo = dask.delayed(Foo)()  # create your expensive thing on the workers instead of locally

def do(row, foo):
    return foo.do(row)

df.apply(do, foo=foo)  # include it as an explicit argument, not a closure within a lambda