【发布时间】:2020-12-30 06:35:48
【问题描述】:
我正在使用 Dataflow 处理具有大约 400 万个特征(总共约 2GB)的 Shapefile 并将几何加载到 BigQuery 中,因此在我的管道开始之前,我将 shapefile 特征提取到一个列表中,并使用 @987654321 初始化管道@。有两种方法可以创建初始功能列表:
- 将每个特征导出为 json 字符串,后续
DoFns 需要将其解析为 dict:
features = [f.ExportToJson() for f in layer]
- 导出从 JSON 字符串预解析的 python dict
features = [json.loads(f.ExportToJson()) for f in layer]
使用选项 1 时,beam.Create(features) 需要一分钟左右,然后管道继续。使用选项 2,beam.Create(features) 在 6 核 i7 上需要 3 多个小时,并且似乎在这里花费了很多时间:
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apache_beam/typehints/trivial_inference.py", line 88, in <listcomp>
typehints.Union[[instance_to_type(v) for k, v in o.items()]],
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apache_beam/typehints/trivial_inference.py", line 88, in instance_to_type
typehints.Union[[instance_to_type(v) for k, v in o.items()]],
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/apache_beam/typehints/trivial_inference.py", line 88, in <listcomp>
这是trivial_inference 在传递字典列表时减慢beam.Create 的原因吗?我可以将beam.Create 配置为不执行它在其中尝试执行的任何操作,或者以其他方式加快它的速度,以使 dicts 列表与字符串列表相比不会慢 100 倍?
【问题讨论】:
-
您可以尝试使用
--no_pipeline_type_check选项运行管道,看看它是否有所不同。
标签: python apache-beam gdal google-dataflow apache-beam-internals