前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Flink 上下游算子并发之间的数据传递方式

Flink 上下游算子并发之间的数据传递方式

作者头像
大数据真好玩
发布2022-06-17 14:01:53
1.4K0
发布2022-06-17 14:01:53
举报

DataStream上游算子向下游算子发送数据的不同方式:

  1. forward (默认)

the output elements are forwarded to the local subtask of the next operation.

上游算子某个并发直接将数据发给同一个slot中的下游算子的并发,

适用于

  • 上下游算子并发度一致
  • 数据没有倾斜
  1. rebalance

the output elements are distributed evenly to instances of the next operation in a round-robin fashion.

按照round-robin的方式,决定上游算子的某个并发的数据发往下游的哪个并发。该方法可以保证从上游算子到下游算子的数据是绝对均匀发送的。但是不同并发之间的数据交互存在网络传输开销。

适用于

  • 上下游算子并发度不一致
  • 存在数据倾斜
  1. shuffle

the output elements are shuffled uniformly randomly to the next operation.

按照均匀分布的随机数,决定上游算子的某个并发的数据发往下游的哪个并发。该方法与rebalance类似,但是会增加随机数生成的开销。并且因为是随机的,最后结果未必是百分百均匀的,但是概率上是均匀分布的。但是不同并发之间的数据交互存在网络传输开销。

适用于

  • 上下游算子并发度不一致
  • 存在数据倾斜
  1. rescale

the output elements are distributed evenly to a subset of instances of the next operation in a round-robin fashion.

The subset of downstream operations to which the upstream operation sends elements depends on the degree of parallelism of both the upstream and downstream operation.

For example, if the upstream operation has parallelism 2 and the downstream operation has parallelism 4, then one upstream operation would distribute elements to two downstream operations while the other upstream operation would distribute to the other two downstream operations. If, on the other hand, the downstream operation has parallelism 2 while the upstream operation has parallelism 4 then two upstream operations will distribute to one downstream operation while the other two upstream operations will distribute to the other downstream operations.

In cases where the different parallelisms are not multiples of each other one or several downstream operations will have a differing number of inputs from upstream operations.

按照分组round-robin的方式,决定上游算子的某个并发的数据发往下游的哪个并发。比如上游算子2并发度,下游4并发度,则每1个上游算子以round robin的方式发送到下游的2个算子;反过来上游算子4并发度,下游2并发度,则2个上游算子的并发度发送到1个下游段子的并发度。如果上下游算子的并发度不成倍数关系,则有几个下游算子的并发的入度可能与其他的并发不同。相比rebalance的好处是:只有部分并发节点之间存在数据传输的开销;坏处是不能很好地解决数据倾斜的问题。

适用于

  • 上下游算子并发度不一致(最好是整数倍)
  1. global

the output values all go to the first instance of the next processing operator. Use this setting with care since it might cause a serious performance bottleneck in the application.

所有上游算子往下游算子的第一个并发发送

可能存在严重的性能问题,一般不用

适用于

  • 所有结果汇总
  1. broadcast

the output elements are broadcast to every parallel instance of the next operation.

所有上游算子的并发产生的数据往每个下游算子的并发发送一份,也就是每个下游算子的并发得到的数据都是全量的。一般要结合BroadcastState来使用,常用于控制流的广播

适用于

  • 控制数据流的广播
  1. keyby

uses the provided key with explicit type information for partitioning its operator states.

每个上游算子的并发产生的数据中抽取key,对key进行hash后发送给对应的下游算子的并发,可以保证同一个key的数据必然发送到同一个下游算子的并发上。但是同一个下游算子可能用于处理多个不同的key,但是这些处理都是分开的

适用于

  • 需要按照key来处理的数据。需要注意,选取key时,要尽量选取能使得数据分散的字段,比如ip、timestamp等等,不要选取如sex等区分数较少的字段
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2022-05-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 大数据真好玩 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档