我正在使用Dataflow处理一个具有大约400万个特性(总共约2GB)的Shapefile,并将几何图形加载到BigQuery中,因此在管道开始之前,我将Shapefile特性提取到一个列表中,并使用beam.Create(features)
初始化管道。有两种方法可以创建初始功能列表:
DoFn
将需要解析为dict:features = [f.ExportToJson() for f in layer]
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>
这是传递dict列表时减慢速度的原因吗?我是否可以将beam.Create
配置为不执行它试图在其中执行的任何操作,或者以其他方式加快它的速度,使dict列表不会比字符串列表慢100倍
非常有趣的结果
我猜这是因为
Create
需要对它接收到的所有数据进行pickle处理。字典的pickle大小可能很大,因为它们被pickle为Python对象,而字符串被pickle为Python字符串你可以做:
避免额外的酸洗。这有用吗
相关问题 更多 >
编程相关推荐