Flink---WaterMark机制

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangguosb/article/details/85112236

背景

 使用Event time时间模型时,由于网络或传输等原因,事件被Flink处理的顺序不一定是事件产生的顺序(乱序),可能会存在两方面影响:

  1. 当前窗口不知道何时停止,开始计算结果;
  2. 影响窗口计算结果的准确性,见示例

WaterMark机制

 WaterMark本质上是一个带有时间戳的特殊event,当Flink中的运算符接收到水印时,它明白(假设)它不会看到比该时间戳更早的消息。

  A Watermark(t) declares that event time has reached time t in that stream, meaning that there should be no more elements from the stream with a timestamp t’ <= t (i.e. events with timestamps older or equal to the watermark).It can then safely compute and emit the result of the window

在这里插入图片描述

生成WaterMark

 WaterMark需要开发人员根据具体的场景采取合适的策略生成;

生成方式:

  1. 数据源中产生;
  2. 在Flink入口处生成( Watermark Generators);

并发WaterMark

场景:一个operator存在多个输入流,可能同时收到多个WaterMark;
处理原则:使用时间戳最小的WaterMark更新当前窗口的Event time,这意味着窗口会等待所有的输入流数据到达才会开始计算;
在这里插入图片描述
参考:

  1. 云邪博客:http://wuchong.me/blog/2018/11/18/flink-tips-watermarks-in-apache-flink-made-easy/
  2. 官网:https://ci.apache.org/projects/flink/flink-docs-release-1.7/dev/event_time.html
  3. https://blog.csdn.net/u013560925/article/details/82499612

猜你喜欢

转载自blog.csdn.net/yangguosb/article/details/85112236