[英]Most efficient way of applying a compute-heavy function to a dask dataframe?
I have a ~6000 rows long dataframe. 我有一个〜6000行长的数据框。 I need to apply a function (let's call it
heavy_func
) to all rows of a specific column, which takes up to a minute per call. 我需要对特定列的所有行应用一个函数(我们称其为
heavy_func
),每次调用最多需要一分钟。 The input to the function is a string, and the output an np.array. 该函数的输入是一个字符串,而输出是一个np.array。
I am using dask distributed
to set up a cluster on which to perform the apply's. 我正在使用
dask distributed
来设置执行应用程序的集群。 Right now I use 80 workers with 4 cores and 8 GB RAM per worker. 现在,我使用80个工作人员,每个工作人员有4个内核和8 GB RAM。
The actual apply step looks like this: 实际的应用步骤如下所示:
ddf = dd.from_pandas(df, npartitions=100)
ddf['new_col'] = ddf.apply(heavy_func, axis=1, meta=('ddf', 'object'))
df = ddf.compute()
I'm wondering how to maximize efficiency here. 我想知道如何在这里最大化效率。
Should I maximize workers or cores? 我应该最大化工作人员或核心人员吗? In what ratio should the nr.
nr应该以什么比例。 of partitions and nr.
分区和nr。 of workers/cores be?
工人/核心是?
I'm also unsure whether using map_partitions
instead of apply
would have any benefits. 我也不确定使用
map_partitions
而不是apply
是否会有任何好处。
For processes and threads you may want to read this: https://docs.dask.org/en/latest/best-practices.html#processes-and-threads 对于进程和线程,您可能需要阅读以下内容: https : //docs.dask.org/en/latest/best-practices.html#processes-and-threads
It depends on how much your computation releases the GIL. 这取决于您的计算释放GIL的程度。
Using apply vs map_partitions shouldn't make much difference here. 在这里使用apply vs map_partitions应该不会有太大的区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.