Flink源码解析系列--Timer定时器

本文深入探讨Flink 1.15-SNAPSHOT版本的TimerService和InternalTimerService,阐述它们在处理时间和事件时间定时器注册、触发及管理中的作用。TimerService通过InternalTimerService实现定时器的分类管理,使用优先队列优化资源消耗,而Event Time定时器依赖水印推进来触发。
摘要由CSDN通过智能技术生成

本文的Flink源码版本为: 1.15-SNAPSHOT,读者可自行从Github clone.

Timer(定时器)是 Flink Streaming API 提供的用于感知并利用 Processing Time/Event Time 变化的机制。Ververica blog上给出的描述如下:

Timers are what make Flink streaming applications reactive and adaptable to processing and event time changes.

对于普通用户来说,最常见的显式利用 Timer 的地方就是 KeyedProcessFunction。我们在其 processElement() 方法中注册 Timer,然后覆写其 onTimer() 方法作为 Timer 触发时的回调逻辑。根据时间特征的不同:

  • 处理时间——调用 Context.timerService().registerProcessingTimeTimer() 注册;onTimer() 在系统时间戳达到 Timer设定的时间戳时触发。
  • 事件时间——调用 Context.timerService().registerEventTimeTimer() 注册;onTimer() 在 Flink 内部水印达到或超过 Timer 设定的时间戳时触发。

TimerService

@PublicEvolving
public interface TimerService {

    String UNSUPPORTED_REGISTER_TIMER_MSG = "Setting timers is only supported on a keyed streams.&
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值