数据流GroupByKey和CoGroupByKey非常慢 [英] Dataflow GroupByKey and CoGroupByKey is very slow

查看:102
本文介绍了数据流GroupByKey和CoGroupByKey非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据流非常适合具有简单转换的管道,但是当我们进行复杂的转换(例如联接)时,性能确实很差.

Dataflow works great for pipelines with simple transforms but when we have complex transforms such as joins the performance is really bad.

推荐答案

我写了这个问题自己回答.

I wrote this question to answer it myself.

引擎盖下发生了什么事

  • 通过PCollection(可序列化对象)之间的数据流传输的发送数据可能不存在于单个计算机中.此外,类似GroupByKey/CoGroupByKey的转换需要将所有数据收集在一个位置,然后再填充结果.
  • 最近,我正在处理具有970列信息的巨大数据集.现在这些数据非常庞大(大约300 GB的PCollecction).在我的用例中,我不得不将此信息与另一个带有CoGroupByKey的PCollection(5列的PCollecction)一起使用,当数据按原样传递时,花了数小时才能准备好数据它甚至可以执行分组操作.

解决方法

  • 减小行的大小,这样您就只有要查询的信息才能加入集合

例如,如果左侧集合中有1个键列,而右侧集合中需要1个值列,则仅将这些信息传递给CoGroupByKey转换.虽然这确实会导致原始集合的数据丢失,但是您将创建一个查找集合,其中包含基于KV的所需信息.

For instance if you have 1 key column in the left collection and need 1 value column from the right collection, pass only those information to the CoGroupByKey Transforms. While this does result in data loss of your original collection, you will have created a lookup collection which has KV based information of what you need.

然后,您可以使用DoFn遍历数据,重建密钥并从作为侧面输入传递的Map中的数据中获取数据.

You can then use a DoFn to traverse over your data, reconstruct the key and fetch the data from the data from the Map passed as side input.

这种方法给出了惊人的结果,它使我能够在5分钟内加入上述数据.

This approached gives amazing results and it enabled me to join the data mentioned above within 5 minutes.

这篇关于数据流GroupByKey和CoGroupByKey非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆