The header of an event defines the event kind as well as the temporal properties of the event.
The event kind indicates whether the event is a new event in the stream or it is declaring the completeness of the existing events in the stream. StreamInsight supports two event kinds: INSERT and CTI (current time increment).
The INSERT event kind adds an event with its payload into the event stream. In addition to the payload, the header of the INSERT event identifies the start and end time for the event. The following diagram shows the layout of an INSERT event kind.
Header | Payload |
|---|
Event kind ::= INSERT StartTime ::= DateTimeOffset EndTime ::= DateTimeOffset | Field 1 … Field n as CLR types |
The CTI event kind is a special punctuation event that indicates the completeness of the existing events in the stream. The CTI event structure consists of a single field that provides a current timestamp. A CTI event serves two purposes:
First, it enables a query to accept and process events whose application timestamps do not correspond to their order of arrival into the query. When a CTI event is issued, it indicates to the StreamInsight server that no subsequent incoming INSERT events will revise the event history before the CTI timestamp. That is, after a CTI event has been issued, no INSERT event can have a start time earlier than the timestamp of the CTI event. This indication of "completeness" of a stream of events enables the StreamInsight server to release the results of windowing or other aggregating operators that have accumulated state, thus ensuring that events flow efficiently through the system.
The second purpose of CTI events is to maintain the low latency of the query. Frequent CTIs will make the query pump out the results at a higher frequency.
Important |
|---|
Without the presence of CTI events in the input stream, no output will be generated from the query. |
For more information, see Advancing Application Time.
The following diagram shows the layout of a CTI event kind.
Header |
|---|
Event kind ::= CTI StartTime ::= DateTimeOffset |
The event model defines the event shape based on its temporal characteristics. StreamInsight supports three event models: interval, point, and edge. Interval events can be seen as the most generic type, of which edge and point are special cases.
Interval
The interval event model represents an event whose payload is valid for a given period of time. The interval event model requires that both the start and end time of the event be provided in the event metadata. Interval events are valid only for this specific time interval. It is important to note that start times are inclusive, whereas end times are exclusive regarding the validity of the event's payload.
The following diagram shows the layout of an interval event model.
Metadata | Payload |
|---|
Event kind ::= INSERT StartTime ::= DateTimeOffset EndTime ::= DateTimeOffset | Field 1 … Field n as CLR types |
Examples of interval events include the width of an electronic pulse, the duration of (validity of) an auction bid, or a stock ticker activity in which the bid price for the stock is valid for a specific time period. In the power monitoring example described above, the power meter event stream may be represented with the following interval events.
Event Kind | Start | End | Payload (Consumption) |
|---|
INSERT | 2009-07-15 09:13:33.317 | 2009-07-15 09:14:09.270 | 100 |
INSERT | 2009-07-15 09:14:09.270 | 2009-07-15 09:14:22.255 | 200 |
INSERT | 2009-07-15 09:14:22.255 | 2009-07-15 09:15:04.987 | 100 |
Point
A point event model represents an event occurrence as of a single point in time. The point event model requires only the start time for the event. The StreamInsight server infers the valid end time by adding a tick (the smallest unit of time in the underlying time data type) to the start time to set the valid time interval for the event. Considering that event end times are exclusive, point events are valid only for the single instant of their start time.
The following diagram shows the layout of a point event model.
Metadata | Payload |
|---|
Event kind ::= INSERT StartTime ::= DateTimeOffset | Field 1 … Field n as CLR types |
Examples of point events include a meter reading, the arrival of an email, a user Web click, a stock tick, or an entry into the Windows Event Log. In the power monitoring example described above, the power meter event stream may be represented with the following point events. Note that the end time is calculated as the start time plus 1 tick (t).
Event Kind | Start | End | Payload (Consumption) |
|---|
INSERT | 2009-07-15 09:13:33.317 | 2009-07-15 09:13:33.317 + t | 100 |
INSERT | 2009-07-15 09:14:09.270 | 2009-07-15 09:14:09.270 + t | 200 |
INSERT | 2009-07-15 09:14:22.255 | 2009-07-15 09:14:22.255 + t | 100 |
Edge
An edge event model represents an event occurrence whose payload is valid for a given interval of time, however, only the start time is known upon arrival to the StreamInsight server; so the end time is set to the maximum time into the future. The end time of the event is known later and updated. The edge event model contains two properties: occurrence time and an edge type. Together, these properties define either the start or end point of the edge event.
The following diagram shows the layout of an edge event model.
Metadata | Payload |
|---|
Event kind ::= INSERT Edge time ::= DateTimeOffset Edge type ::= START | END | Field 1 … Field n as CLR types |
Examples of edge events are Windows processes, trace events from Event Tracing for Windows (ETW), a Web user session, or quantization of an analog signal. The valid time interval for the payload of an edge event is the difference between the timestamp of the Start event and the timestamp of the End event. In the following diagram, notice that the event with a payload value of 'c' does not have a known end date at this point in time.
Event Kind | Edge Type | Start Time | End Time | Payload |
|---|
INSERT | Start | t0 | DateTimeOffset.MaxValue | a |
INSERT | End | t0 | t1 | a |
INSERT | Start | t1 | DateTimeOffset.MaxValue | b |
INSERT | End | t1 | t3 | b |
INSERT | Start | t3 | DateTimeOffset.MaxValue | c |
… and so on | | | | |
The following illustration shows the quantization of an analog signal using edge events based on the start and end times defined in the table above. Such a continuous signal implies that for every new value, both an END as well as a START edge must be submitted. The described edges in the illustration refer to the event from time t1 to t3.
.gif)
Performance Considerations Related to the Choice of Event Model
It is important to choose the right event model for your problem. For instance, if you have events that last for a period of time, and your application has the ability to determine both the start and end times of the event, it is better to use interval events to model this. If you have a scenario where you do not know the end time of an event at event arrival, you could consider modeling the event as a point event, alter its lifetime to extend for a period of time, and then use the Clip operation to modify the lifetime when that event’s end is recognized. The other alternative to consider is to model these events as edge events.
While edge events are a very convenient event model, there are a couple of performance implications you should be aware of. Processing edge events works best when these events arrive fully ordered – i.e. all start edges are ordered on start time and end edges on end time and the combined sequence of events is also ordered on time. For example, if you have a sequence of edge events as follows:
Event Kind | Edge Type | Start Time | End Time | Payload |
INSERT | Start | 1 | DateTimeOffset.MaxValue | a |
INSERT | End | 1 | 10 | a |
INSERT | Start | 3 | DateTimeOffset.MaxValue | b |
INSERT | End | 3 | 6 | b |
INSERT | Start | 5 | DateTimeOffset.MaxValue | c |
INSERT | End | 5 | 20 | c |
This sequence is unordered on timestamps (1, 10, 3, 6, 5, 20). Instead if the edge events were fully ordered - as in (1, 3, 5, 6, 10, 20) – this will have a lesser performance impact on query processing. Enabling such an ordering followed by processing is easily achieved. Split the problem into two queries. The first query can be an empty query that receives edge events as input, fully orders them, and outputs these ordered edge events. The second query can take this input and perform the main logic. Note that these should be defined as two separate queries, and then joined together using dynamic query composition. For more information, see Composing Queries at Runtime.