时间模型
Flink提供了3种时间模型如下图所示,常用的为Processing time和Event time;
Event time
含义: 事件产生的时间, 反映了事件产生的先后顺序 ;
注意:
- Event time是指产生事件的外部设备的时间,并非Flink机器上的时间;
- Event time需要从事件数据的特定字段获取;
- 由于传输或网络的原因,Flink处理事件的顺序不一定与事件产生的顺序一致;
The order of events based on event time is often not the same as the order based on processing time; that is, events arrive at the stream processor out of order.
生成方式:
- 由产生事件的设备生成,嵌入在事件数据中,然后Flink通过特定的字段获取即可(推荐);
- 使用Flink提供的接口生成(实际上应该称为Ingestion time);
Often, a third notion of time called ingestion time or ingress time is used, referring to the time that the event enters the stream processing framework. Data that lacks a true event time may be assigned a time, but these timestamps are simply assigned by the stream processor when it first sees the event (in the source function, the first operator of the program).
Processing time
含义: Flink处理事件的时间,反映了事件被Flink处理的先后顺序;
应用场景
根据不同的应用场景选取不同的时间模型。如果业务处理逻辑跟事件产生的先后顺序有关,则采用Event time比如实时流媒体;如果业务处理逻辑跟事件处理的先后顺序有关,则采用Processing time,比如实时告警;
参考: