Dask在单核上的缓慢计算性能

问题描述 投票:0回答:1

我实现了一个map函数,该函数将字符串解析为XML树,遍历该树并提取一些信息。如果不是那么多的东西,没有其他的IO代码。

我们从Dask获得的加速效果不是很令人满意,因此我们仔细研究了单个分区中单个但很大的项目(580 MB XML字符串)的原始执行性能。

这里是代码:

def timedMap(x):
  start = time.time()
  # computation, no IO or access to Dask variables, no threading or multiprocessing
  ...
  return time.time() - start

print("Direct Execution")
print(timedMap(xml_string))

print("Dask Distributed")
import dask
from dask.distributed import Client
client = Client(threads_per_worker=1, n_workers=1)
print(client.submit(timedMap, xml_string).result())
client.close()

print("Dask Multiprocessing")
import dask.bag as db
bag = db.from_sequence([xml_string], npartitions=1)
print(bag.map(timedMap).compute()[0])

输出(没有前/后开销的时间是:

Direct Execution
54.59478211402893
Dask Distributed
91.79525017738342
Dask Multiprocessing
86.94628381729126

我已经重复了很多次。看来Dask不仅在通信和任务管理上有开销,而且各个计算步骤也显着变慢。

为什么Dask中的计算速度这么慢?我怀疑分析器并将分析间隔从10毫秒增加到1000毫秒,这敲了5秒。但是,仍然...然后我怀疑内存压力很大,但是工作人员没有达到极限,甚至没有达到50%。

就开销而言(测量提交,结果和map + compute的总时间),Dask在分布式案例中增加了18秒,在多处理案例中增加了3秒。我很乐意为此付出开销,但是我不希望实际的计算花费那么长的时间。您是否知道为什么会这样?我该如何调整以加快速度?

注意:当我将计算负荷增加一倍时,所有持续时间也大致会增加一倍。

祝您一切顺利,鲍里斯

python dask dask-distributed
1个回答
0
投票

您不应期望任何加速,因为您只有一个分区。

您应该会有所放缓,因为您正在Python的各个进程之间移动500MB。我建议您阅读以下内容:https://docs.dask.org/en/latest/best-practices.html#load-data-with-dask

© www.soinside.com 2019 - 2024. All rights reserved.