dask computation not executing in parallel

混江龙づ霸主 提交于 2019-12-10 03:53:59

问题


I have a directory of json files that I am trying to convert to a dask DataFrame and save it to castra. There are 200 files containing O(10**7) json records between them. The code is very simple largely following tutorial examples.

import dask.dataframe as dd
import dask.bag as db
import json
txt = db.from_filenames('part-*.json')
js = txt.map(json.loads)
df = js.to_dataframe()
cs=df.to_castra("data.castra")

I am running it on a 32 core machine, but the code only utilizes one core at 100%. My understanding from the docs is that this code execute in parallel. Why is it not? Did I misunderstand something?


回答1:


Your final collection is a dask dataframe, which uses threads by default, you will have to explicitly tell dask to use processes.

You can do this globally

import dask
dask.config.set(scheduler='multiprocessing')

Or do this just on the to_castra call

df.to_castra("data.castra", scheduler='multiprocessing')

Also, just as a warning, Castra was mostly an experiment. It's decently fast but also not nearly mature as something like HDF5 or Parquet.



来源:https://stackoverflow.com/questions/35516305/dask-computation-not-executing-in-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!