SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Downloaden Sie, um offline zu lesen
Design Patterns for
Complex Event
Processing (CEP)
Alexandre Alves
Shailendra Mishra
Oracle Corporation
Agenda
>   Building blocks
>   Design Patterns
>   Conclusion




                      2
Building blocks
>   EVENT
     Defined by a schema (i.e. event type)
     Tuple of event properties

                                             Event properties
             StockEventType
             symbol     string
             lastBid    float
             lastAsk    float




                                                                3
Building blocks
>   STREAM
     Time ordered sequence of events in time

     APPEND-only
       One cannot remove events, just add them to the sequence

     Unbounded
        There is no end to the sequence
     {event1, event2, event3, event4, …, eventN}




                                                                 4
Building blocks
>   STREAM
     Examples:

       {{1s, event1}, {2s, event2}, {4s, event3}}
          Valid STREAM



       {{1s, event1}, {4s, event2}, {2s, event3}}
          Not a STREAM, this is a EVENT CLOUD.




                                                    5
Building blocks
>   RELATION
     Bag of events at some instantaneous time T
     Allow for INSERT, DELETE, and UPDATE
     Example:
       At T=1: {{event1}, {event2}, {event3}}
       At T=2: {{event1}, {event3}, {event4}}
         No changes to event1 and event3
         Event2 was deleted
         Event4 was inserted




                                                  6
Building blocks
>   OPERATORS
     Transform STREAMS and RELATIONS
     Types of operators:
      RELATION to RELATION
        Well-known from RDBMS (e.g. project, filter, join)
      STREAM to RELATION
        WINDOW operator bounds STREAMS into RELATIONS (e.g.
        NOW)
      RELATION TO STREAM
      STREAM to STREAM



                                                              7
Summary
>   CEP is about continuous processing of online
    streaming events

>   STREAM is a APPEND-only time-ordered
    sequence of events

>   RELATION is a INSERT/DELETE/UPDATE-able
    bag of events at some time t



                                                   8
Design Patterns
>   Event Filtering
>   New event detection
>   Event partitioning
>   Event enrichment
>   Event aggregation
>   Event correlation
>   Application-time events
>   Missing event detection


                              9
1. Event filtering
>   Problem:
      Look for specific data on a stream, dropping the
      unwanted events.

>   Scenario:
      Consider STOCKSTREAM a stream of stock events
      (symbol, lastBid, lastAsk)

      Look for all stocks whose symbol is ‘AAA’


                                                         10
1. Event filtering

     Time   Input                 Output

     1      {“AAA”, 10.0, 10.5}   {“AAA”, 10.0, 10.5}


     2      {“AAA”, 10.0, 10.5}   {“AAA”, 10.0, 10.5}


     3      {“BBB”, 11.0, 12.5}




                                                        11
1. Event filtering
                                 Specify STREAM source
>   Solution:
                                                Specify a WINDOW operator
    SELECT *
    FROM stockstream [NOW]
    WHERE symbol = ‘AAA’

Define predicate for filtering




                                                                            12
1. Event filtering
>   Why do we need the window operator [NOW]?
       Filtering works on relations, hence we need to convert the
       stock stream into a relation.
       Logically this makes sense, as you cannot work on a
       unbound set of things, you need to constraint it to a
       bounded set.

       Note that in some cases short-cuts are allowed; for
       example, where [NOW] is assumed if not specified.




                                                                    13
2. New event detection
>   Problem:
      Look for specific data on a stream, notify only if it is
      new data

>   Scenario:
      Report only those stocks whose price have
      changed since the last event




                                                                 14
2. New event detection


    Time   Input                 Output

    1      {“AAA”, 10.0, 10.5}   {“AAA”, 10.0, 10.5}

    2      {“AAA”, 10.0, 10.5}

    3      {“BBB”, 11.0, 12.5}   {“BBB”, 11.0, 12.5}




                                                       15
2. New event detection
>   SELECT * FROM stockstream [NOW]
     Generates RELATION or STREAM?
     Generates a RELATION, which includes all events
     at time t
     What we need are the events that exist at time t,
     but do not exist at time (t - 1)
     Use RELATION-STREAM operator ISTREAM
     (insert stream)
     As we are interested on the last event, use the
     window operator [ROWS 1] instead of [NOW].

                                                         16
2. New event detection
>   Solution

    ISTREAM(
      SELECT *
      FROM stockstream [ROWS 1]
    )




                                  17
Although similar to event at t=2,
3. Event partitioning                    it is != then event at t=3…


>   There is a problem with the current solution…


       Time    Input                  Output

       1        {“AAA”, 10.0, 10.5}   {“AAA”, 10.0, 10.5}

       2        {“AAA”, 10.0, 10.5}

       3        {“BBB”, 11.0, 12.5}   {“BBB”, 11.0, 12.5}

       4        {“AAA”, 10.0, 10.5}   {“AAA”, 10.0, 10.5}


                                                                         18
3. Event partitioning
>   We need to partition the window by stock symbol

    ISTREAM (
        SELECT *
        FROM stockstream
         [PARTITION BY symbol ROWS 1]
    )




                                                      19
3. Event partitioning

    Time   Input                 Output

    1      {“AAA”, 10.0, 10.5}   {“AAA”, 10.0, 10.5}

    2      {“AAA”, 10.0, 10.5}

    3      {“BBB”, 11.0, 12.5}   {“BBB”, 11.0, 12.5}

    4      {“AAA”, 10.0, 10.5}




                                                       20
4. Event enrichment
>   Problem:
      Enrich events from a stream with (somewhat) static data from
      a relation.

>   Scenario:
      Consider STOCKRELATION (relation):
              symbol,
              company full-name,
              headquarters' location

      For every stock event from STOCKSTREAM whose lastBid is
      greaten than 5.0, find its company’s location.

                                                                 21
4. Event enrichment                    Query is trigged by stream,
                                       and not by relation
    STOCKRELATION

    Symbol               Full-name         Location
    AAA                  The AAA company   San Francisco

    BBB                  The BBB company   San Jose



    Time     Input (STOCKSTREAM)     Output (QUERY)
    1
             {“AAA”, 10.0, 10.5}     {“AAA”, “San Francisco”}
    2
             {“BBB”, 11.0, 12.5}     {“BBB”, “San Jose”}
    3
             {“AAA”, 4.0, 4.5}


                                                                     22
4. Event enrichment
>   Solution:
      SELECT event.symbol, location
      FROM stockstream [NOW] AS event,
          stockrelation AS data
      WHERE event.symbol = data.symbol AND
           event.lastBid > 5.0
      Why do we need to specify a WINDOW operator for
      the STREAM and not for the RELATION?
        Because a RELATION is instantaneous, it is already
        bound to time t.
5. Event aggregation
>   Problem:
      Aggregate several (simple) events from a stream
      into a single new (complex) event summarizing
      event properties of the simple events

>   Scenario:
      Output the average bid and ask price of a stock of
      the last 10 seconds.




                                                           24
5. Event aggregation                   The event for AAA is also
                                       included in the result



   Time   Input                 Output

   1s     {“AAA”, 10.0, 12.0}   {“AAA”, 10.0, 12.0}

   4s     {“AAA”, 12.0, 14.0}   {“AAA”, 11.0, 13.0}

                                {“AAA”, 11.0, 13},
   9s     {“BBB”, 4.0, 5.0}
                                {“BBB”, 4.0, 5.0}
   15s    {“BBB”, 8.0, 10.0}    {“BBB”, 6.0, 7.5}
                                  > 10s
   20s                          {“BBB”, 8.0, 10.0}


                                                                   25
5. Event aggregation
>   Solution:
    SELECT symbol, AVG(lastBid), AVG(lastAsk)
    FROM stockstream [RANGE 10 seconds]
    GROUP BY symbol

     The RANGE WINDOW operator is a STREAM to RELATION
     operator
        It defines a range of time in which events are kept, events older
        than range are removed from window.

     As we are interested on the average price per symbol, we
     need to use the GROUP BY operator.
6. Event correlation
>   Problem:
      Correlate events from one or several streams on a common
      set of values, that is, a common pattern.

>   Scenario:
      Consider a BIDSTREAM and ASKSTREAM, respectively
      containing bid (symbol, bidPrice, customer) and ask requests
      (symbol, askPrice, customer).
      Correlate bids with asks that are related to same symbol and
      occurring within 10 seconds of each other; anything older is
      considered stale.




                                                                     27
6. Event correlation

Time   Input (BIDS)           Input (ASKS)           Output


1s     {“AAA”, 12.0, cust1}   {“BBB”, 9.0, cust2}


                                                     {“AAA”, 10.0, cust3, 10.0, cust2}
5s     {“AAA”, 10.0, cust3}   {“AAA”, 10.0, cust2}
                                                     {“AAA”, 12.0, cust1, 10.0, cust2}
                                 > 10s
15s    {“BBB”, 10.0, cust4}   {“CCC”, 11.0, cust5}   {“AAA”, 10.0, cust3, 10.0, cust2}



20s                           {“BBB”, 10.0, cust6}   {“BBB”, 10.0, cust4, 10.0, cust6}




                                                                                         28
6. Event correlation
>   Solution:
    SELECT bid.symbol, bidPrice, bid.cust, askPrice, ask.cust,
    FROM bidstream [RANGE 10 seconds] AS bid,
           askstream [RANGE 10 seconds] AS ask
    WHERE bid.symbol = ask.symbol


      You can perform regular join operations between streams, including
      outer joins.
7. Application time
>   Problem:
      Need to use application’s view of time, instead of
      CPU wall-clock.
      This is particularly useful when events originate
      from different machines and need some way of
      synchronizing.
>   Scenario:
      Again, consider bid and ask stream…
      However, bid and ask requests are time-stamped
      on trader at the time that the order is placed.
7. Application time
>   Seller places two ask requests respectively at time 8:00:00
    and 8:00:12
>   Buyer places one bid request at time 8:00:11
7. Application time
>   Remember that we want to correlate using a 10 seconds
    window, as anything older is stale…
>   Hence first event from seller should not be considered,
    and we should correlate the ask price of 11.0 with the bid
    price of 9.5
7. Application time
>   However, the reality is that the first two events could arrive
    together in a burst in the exchange, and the third could be
    delayed in the cloud…
7. Application time
>   In this case, bid price of 9.5 would correlate to ask price of
    10.0 and the exchange would loose money as the spread
    is lower…
7. Application time
>   Solution:
      The query does not change…
      However STREAMS must be configured to use application
      time-stamps based upon some event property, instead of
      having events being system-timestamped…

                           BidEventType
                           symbol        string
                           customer      string
                           bidPrice      float
                           orderTime     dateTime
8. Missing event detection
>   Problem:
      Alert if an expected event is missing after some
      amount of time.

>   Scenario:
      Consider a SALESTREAM stream, containing
      transaction type (customer order or shipment), and
      order id.
      Alert if an order is not followed by a shipment within
      10 seconds.

                                                               36
8. Missing event detection
     Time   Input               Output
     1s     {1, “ORDER”}

     5s     {2, “ORDER”}

     10s    {1, “SHIPMENT”}   10s
     15s    {3, “ORDER”}
     15+t
                                    {“DELAYED”, 2}
     20s    {3, “SHIPMENT”}



                                                     37
8. Missing event detection
>   Solution:
    SELECT "DELAYED" as alertType, orders.orderId,
    FROM salestream MATCH_RECOGNIZE (
        PARTITION BY orderId

         MEASURES
               CustOrder.orderId AS orderId

         PATTERN (CustOrder NotTheShipment*) DURATION 10 SECONDS

         DEFINE
                  CustOrder AS (type = ‘ORDER’),
                  NotTheShipment AS ((NOT (eventType = ‘ SHIPMENT’)))

    ) AS orders
Conclusion
>   Online processing, that is, no need to store to disk first
>   Declarative approach
>   Able to deal with unbounded data-sets (streams)
>   Powerful temporal constructs
>   Able to find complex relationships using pattern matching
>   Leverage Relational algebra from DBMS by means of
    converting STREAM-RELATION and RELATION-
    STREAM
>   Rich library of event processing design patterns
Alexandre Alves
Shailendra Mishra
Oracle Corporation




                     40

Weitere ähnliche Inhalte

Andere mochten auch

古き良き街 「 京都 」
古き良き街 「 京都 」古き良き街 「 京都 」
古き良き街 「 京都 」aoshin-home
 
Luopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksi
Luopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksiLuopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksi
Luopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksiKouluterveyskysely
 
Biotechnology Virtual Lab.Day 2a
Biotechnology Virtual Lab.Day 2aBiotechnology Virtual Lab.Day 2a
Biotechnology Virtual Lab.Day 2ajmori1
 
био сумки
био сумкибио сумки
био сумкиtrav-ve
 
Inadimplência do consumidor, professor Samy Dana.
Inadimplência do consumidor, professor Samy Dana.Inadimplência do consumidor, professor Samy Dana.
Inadimplência do consumidor, professor Samy Dana.FGV-EAESP
 
التطهير العرقي والإبادة الجماعية الشركسية - الجزء الأول
التطهير العرقي والإبادة الجماعية الشركسية - الجزء الأولالتطهير العرقي والإبادة الجماعية الشركسية - الجزء الأول
التطهير العرقي والإبادة الجماعية الشركسية - الجزء الأولWalid Hakouz
 
Intro to Inbound: Creating Buyer Personas
Intro to Inbound: Creating Buyer PersonasIntro to Inbound: Creating Buyer Personas
Intro to Inbound: Creating Buyer Personaskyasi
 
Cells homeostasis_and_disease
Cells  homeostasis_and_diseaseCells  homeostasis_and_disease
Cells homeostasis_and_diseasellVictorGmll
 

Andere mochten auch (20)

古き良き街 「 京都 」
古き良き街 「 京都 」古き良き街 「 京都 」
古き良き街 「 京都 」
 
Slums
SlumsSlums
Slums
 
Pay it forward 2
Pay it forward 2Pay it forward 2
Pay it forward 2
 
Luopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksi
Luopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksiLuopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksi
Luopa: Kaikki mukaan! Yhteisöllisyys Helsingin peruskoulujen voimavaraksi
 
Digg power point
Digg power pointDigg power point
Digg power point
 
Biotechnology Virtual Lab.Day 2a
Biotechnology Virtual Lab.Day 2aBiotechnology Virtual Lab.Day 2a
Biotechnology Virtual Lab.Day 2a
 
Arbitros
ArbitrosArbitros
Arbitros
 
05974812
0597481205974812
05974812
 
био сумки
био сумкибио сумки
био сумки
 
Inadimplência do consumidor, professor Samy Dana.
Inadimplência do consumidor, professor Samy Dana.Inadimplência do consumidor, professor Samy Dana.
Inadimplência do consumidor, professor Samy Dana.
 
Garden isles
Garden islesGarden isles
Garden isles
 
التطهير العرقي والإبادة الجماعية الشركسية - الجزء الأول
التطهير العرقي والإبادة الجماعية الشركسية - الجزء الأولالتطهير العرقي والإبادة الجماعية الشركسية - الجزء الأول
التطهير العرقي والإبادة الجماعية الشركسية - الجزء الأول
 
Intro to Inbound: Creating Buyer Personas
Intro to Inbound: Creating Buyer PersonasIntro to Inbound: Creating Buyer Personas
Intro to Inbound: Creating Buyer Personas
 
Pda
PdaPda
Pda
 
Puy chosuantai2
Puy chosuantai2Puy chosuantai2
Puy chosuantai2
 
Me and my goals
Me and my goalsMe and my goals
Me and my goals
 
5 2
5 25 2
5 2
 
Epics
EpicsEpics
Epics
 
Cells homeostasis_and_disease
Cells  homeostasis_and_diseaseCells  homeostasis_and_disease
Cells homeostasis_and_disease
 
Vracev Gaj3
Vracev Gaj3Vracev Gaj3
Vracev Gaj3
 

Ähnlich wie Ts 4783 1

WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor
WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor
WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor WSO2
 
Introducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event ProcessorIntroducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event ProcessorWSO2
 
Deep dive into stateful stream processing in structured streaming by Tathaga...
Deep dive into stateful stream processing in structured streaming  by Tathaga...Deep dive into stateful stream processing in structured streaming  by Tathaga...
Deep dive into stateful stream processing in structured streaming by Tathaga...Databricks
 
TSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkTSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkAnirudh Todi
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesKeshav Murthy
 
Flink 0.10 @ Bay Area Meetup (October 2015)
Flink 0.10 @ Bay Area Meetup (October 2015)Flink 0.10 @ Bay Area Meetup (October 2015)
Flink 0.10 @ Bay Area Meetup (October 2015)Stephan Ewen
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioGioia Ballin
 
WSO2 Product Release Webinar - WSO2 Complex Event Processor
WSO2 Product Release Webinar - WSO2 Complex Event ProcessorWSO2 Product Release Webinar - WSO2 Complex Event Processor
WSO2 Product Release Webinar - WSO2 Complex Event ProcessorWSO2
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streamsBartosz Sypytkowski
 
Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features WSO2
 
Socrates BE - Projections Explained
Socrates BE - Projections ExplainedSocrates BE - Projections Explained
Socrates BE - Projections ExplainedYves Reynhout
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and SymfonyIgnacio Martín
 
Serverless Stateful Architecture
Serverless Stateful ArchitectureServerless Stateful Architecture
Serverless Stateful ArchitecturePatrick Di Loreto
 
Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...
Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...
Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...Flink Forward
 
WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0
WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0
WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0WSO2
 

Ähnlich wie Ts 4783 1 (20)

WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor
WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor
WSO2 Product Release Webinar - Introducing the WSO2 Complex Event Processor
 
Introducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event ProcessorIntroducing the WSO2 Complex Event Processor
Introducing the WSO2 Complex Event Processor
 
Deep dive into stateful stream processing in structured streaming by Tathaga...
Deep dive into stateful stream processing in structured streaming  by Tathaga...Deep dive into stateful stream processing in structured streaming  by Tathaga...
Deep dive into stateful stream processing in structured streaming by Tathaga...
 
TSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech TalkTSAR (TimeSeries AggregatoR) Tech Talk
TSAR (TimeSeries AggregatoR) Tech Talk
 
Tsar tech talk
Tsar tech talkTsar tech talk
Tsar tech talk
 
IBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql FeaturesIBM Informix dynamic server 11 10 Cheetah Sql Features
IBM Informix dynamic server 11 10 Cheetah Sql Features
 
Flink 0.10 @ Bay Area Meetup (October 2015)
Flink 0.10 @ Bay Area Meetup (October 2015)Flink 0.10 @ Bay Area Meetup (October 2015)
Flink 0.10 @ Bay Area Meetup (October 2015)
 
A dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenarioA dive into akka streams: from the basics to a real-world scenario
A dive into akka streams: from the basics to a real-world scenario
 
WSO2 Product Release Webinar - WSO2 Complex Event Processor
WSO2 Product Release Webinar - WSO2 Complex Event ProcessorWSO2 Product Release Webinar - WSO2 Complex Event Processor
WSO2 Product Release Webinar - WSO2 Complex Event Processor
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streams
 
Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features Complex Event Processor 3.0.0 - An overview of upcoming features
Complex Event Processor 3.0.0 - An overview of upcoming features
 
Socrates BE - Projections Explained
Socrates BE - Projections ExplainedSocrates BE - Projections Explained
Socrates BE - Projections Explained
 
Solving the n + 1 query problem
Solving the n + 1 query problemSolving the n + 1 query problem
Solving the n + 1 query problem
 
Server side rendering with React and Symfony
Server side rendering with React and SymfonyServer side rendering with React and Symfony
Server side rendering with React and Symfony
 
Serverless stateful
Serverless statefulServerless stateful
Serverless stateful
 
Serverless Stateful Architecture
Serverless Stateful ArchitectureServerless Stateful Architecture
Serverless Stateful Architecture
 
About time
About timeAbout time
About time
 
Wait events
Wait eventsWait events
Wait events
 
Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...
Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...
Flink Forward SF 2017: Stefan Richter - Improvements for large state and reco...
 
WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0
WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0
WSO2 Product Release Webinar: WSO2 Complex Event Processor 4.0
 

Mehr von Alexandre de Castro Alves

Mehr von Alexandre de Castro Alves (7)

A Guideline to Statistical and Machine Learning
A Guideline to Statistical and Machine LearningA Guideline to Statistical and Machine Learning
A Guideline to Statistical and Machine Learning
 
Developing Modular Systems using OSGi
Developing Modular Systems using OSGiDeveloping Modular Systems using OSGi
Developing Modular Systems using OSGi
 
Speeding up big data with event processing
Speeding up big data with event processingSpeeding up big data with event processing
Speeding up big data with event processing
 
A General Extension System for Event Processing Languages
A General Extension System for Event Processing LanguagesA General Extension System for Event Processing Languages
A General Extension System for Event Processing Languages
 
Bpel4 Ws 1.1 To Ws Bpel 2.0
Bpel4 Ws 1.1 To Ws Bpel 2.0Bpel4 Ws 1.1 To Ws Bpel 2.0
Bpel4 Ws 1.1 To Ws Bpel 2.0
 
Introduction to OSGi
Introduction to OSGiIntroduction to OSGi
Introduction to OSGi
 
Alves Mea Pch1 Free
Alves Mea Pch1 FreeAlves Mea Pch1 Free
Alves Mea Pch1 Free
 

Ts 4783 1

  • 1. Design Patterns for Complex Event Processing (CEP) Alexandre Alves Shailendra Mishra Oracle Corporation
  • 2. Agenda > Building blocks > Design Patterns > Conclusion 2
  • 3. Building blocks > EVENT Defined by a schema (i.e. event type) Tuple of event properties Event properties StockEventType symbol string lastBid float lastAsk float 3
  • 4. Building blocks > STREAM Time ordered sequence of events in time APPEND-only One cannot remove events, just add them to the sequence Unbounded There is no end to the sequence {event1, event2, event3, event4, …, eventN} 4
  • 5. Building blocks > STREAM Examples: {{1s, event1}, {2s, event2}, {4s, event3}} Valid STREAM {{1s, event1}, {4s, event2}, {2s, event3}} Not a STREAM, this is a EVENT CLOUD. 5
  • 6. Building blocks > RELATION Bag of events at some instantaneous time T Allow for INSERT, DELETE, and UPDATE Example: At T=1: {{event1}, {event2}, {event3}} At T=2: {{event1}, {event3}, {event4}} No changes to event1 and event3 Event2 was deleted Event4 was inserted 6
  • 7. Building blocks > OPERATORS Transform STREAMS and RELATIONS Types of operators: RELATION to RELATION Well-known from RDBMS (e.g. project, filter, join) STREAM to RELATION WINDOW operator bounds STREAMS into RELATIONS (e.g. NOW) RELATION TO STREAM STREAM to STREAM 7
  • 8. Summary > CEP is about continuous processing of online streaming events > STREAM is a APPEND-only time-ordered sequence of events > RELATION is a INSERT/DELETE/UPDATE-able bag of events at some time t 8
  • 9. Design Patterns > Event Filtering > New event detection > Event partitioning > Event enrichment > Event aggregation > Event correlation > Application-time events > Missing event detection 9
  • 10. 1. Event filtering > Problem: Look for specific data on a stream, dropping the unwanted events. > Scenario: Consider STOCKSTREAM a stream of stock events (symbol, lastBid, lastAsk) Look for all stocks whose symbol is ‘AAA’ 10
  • 11. 1. Event filtering Time Input Output 1 {“AAA”, 10.0, 10.5} {“AAA”, 10.0, 10.5} 2 {“AAA”, 10.0, 10.5} {“AAA”, 10.0, 10.5} 3 {“BBB”, 11.0, 12.5} 11
  • 12. 1. Event filtering Specify STREAM source > Solution: Specify a WINDOW operator SELECT * FROM stockstream [NOW] WHERE symbol = ‘AAA’ Define predicate for filtering 12
  • 13. 1. Event filtering > Why do we need the window operator [NOW]? Filtering works on relations, hence we need to convert the stock stream into a relation. Logically this makes sense, as you cannot work on a unbound set of things, you need to constraint it to a bounded set. Note that in some cases short-cuts are allowed; for example, where [NOW] is assumed if not specified. 13
  • 14. 2. New event detection > Problem: Look for specific data on a stream, notify only if it is new data > Scenario: Report only those stocks whose price have changed since the last event 14
  • 15. 2. New event detection Time Input Output 1 {“AAA”, 10.0, 10.5} {“AAA”, 10.0, 10.5} 2 {“AAA”, 10.0, 10.5} 3 {“BBB”, 11.0, 12.5} {“BBB”, 11.0, 12.5} 15
  • 16. 2. New event detection > SELECT * FROM stockstream [NOW] Generates RELATION or STREAM? Generates a RELATION, which includes all events at time t What we need are the events that exist at time t, but do not exist at time (t - 1) Use RELATION-STREAM operator ISTREAM (insert stream) As we are interested on the last event, use the window operator [ROWS 1] instead of [NOW]. 16
  • 17. 2. New event detection > Solution ISTREAM( SELECT * FROM stockstream [ROWS 1] ) 17
  • 18. Although similar to event at t=2, 3. Event partitioning it is != then event at t=3… > There is a problem with the current solution… Time Input Output 1 {“AAA”, 10.0, 10.5} {“AAA”, 10.0, 10.5} 2 {“AAA”, 10.0, 10.5} 3 {“BBB”, 11.0, 12.5} {“BBB”, 11.0, 12.5} 4 {“AAA”, 10.0, 10.5} {“AAA”, 10.0, 10.5} 18
  • 19. 3. Event partitioning > We need to partition the window by stock symbol ISTREAM ( SELECT * FROM stockstream [PARTITION BY symbol ROWS 1] ) 19
  • 20. 3. Event partitioning Time Input Output 1 {“AAA”, 10.0, 10.5} {“AAA”, 10.0, 10.5} 2 {“AAA”, 10.0, 10.5} 3 {“BBB”, 11.0, 12.5} {“BBB”, 11.0, 12.5} 4 {“AAA”, 10.0, 10.5} 20
  • 21. 4. Event enrichment > Problem: Enrich events from a stream with (somewhat) static data from a relation. > Scenario: Consider STOCKRELATION (relation): symbol, company full-name, headquarters' location For every stock event from STOCKSTREAM whose lastBid is greaten than 5.0, find its company’s location. 21
  • 22. 4. Event enrichment Query is trigged by stream, and not by relation STOCKRELATION Symbol Full-name Location AAA The AAA company San Francisco BBB The BBB company San Jose Time Input (STOCKSTREAM) Output (QUERY) 1 {“AAA”, 10.0, 10.5} {“AAA”, “San Francisco”} 2 {“BBB”, 11.0, 12.5} {“BBB”, “San Jose”} 3 {“AAA”, 4.0, 4.5} 22
  • 23. 4. Event enrichment > Solution: SELECT event.symbol, location FROM stockstream [NOW] AS event, stockrelation AS data WHERE event.symbol = data.symbol AND event.lastBid > 5.0 Why do we need to specify a WINDOW operator for the STREAM and not for the RELATION? Because a RELATION is instantaneous, it is already bound to time t.
  • 24. 5. Event aggregation > Problem: Aggregate several (simple) events from a stream into a single new (complex) event summarizing event properties of the simple events > Scenario: Output the average bid and ask price of a stock of the last 10 seconds. 24
  • 25. 5. Event aggregation The event for AAA is also included in the result Time Input Output 1s {“AAA”, 10.0, 12.0} {“AAA”, 10.0, 12.0} 4s {“AAA”, 12.0, 14.0} {“AAA”, 11.0, 13.0} {“AAA”, 11.0, 13}, 9s {“BBB”, 4.0, 5.0} {“BBB”, 4.0, 5.0} 15s {“BBB”, 8.0, 10.0} {“BBB”, 6.0, 7.5} > 10s 20s {“BBB”, 8.0, 10.0} 25
  • 26. 5. Event aggregation > Solution: SELECT symbol, AVG(lastBid), AVG(lastAsk) FROM stockstream [RANGE 10 seconds] GROUP BY symbol The RANGE WINDOW operator is a STREAM to RELATION operator It defines a range of time in which events are kept, events older than range are removed from window. As we are interested on the average price per symbol, we need to use the GROUP BY operator.
  • 27. 6. Event correlation > Problem: Correlate events from one or several streams on a common set of values, that is, a common pattern. > Scenario: Consider a BIDSTREAM and ASKSTREAM, respectively containing bid (symbol, bidPrice, customer) and ask requests (symbol, askPrice, customer). Correlate bids with asks that are related to same symbol and occurring within 10 seconds of each other; anything older is considered stale. 27
  • 28. 6. Event correlation Time Input (BIDS) Input (ASKS) Output 1s {“AAA”, 12.0, cust1} {“BBB”, 9.0, cust2} {“AAA”, 10.0, cust3, 10.0, cust2} 5s {“AAA”, 10.0, cust3} {“AAA”, 10.0, cust2} {“AAA”, 12.0, cust1, 10.0, cust2} > 10s 15s {“BBB”, 10.0, cust4} {“CCC”, 11.0, cust5} {“AAA”, 10.0, cust3, 10.0, cust2} 20s {“BBB”, 10.0, cust6} {“BBB”, 10.0, cust4, 10.0, cust6} 28
  • 29. 6. Event correlation > Solution: SELECT bid.symbol, bidPrice, bid.cust, askPrice, ask.cust, FROM bidstream [RANGE 10 seconds] AS bid, askstream [RANGE 10 seconds] AS ask WHERE bid.symbol = ask.symbol You can perform regular join operations between streams, including outer joins.
  • 30. 7. Application time > Problem: Need to use application’s view of time, instead of CPU wall-clock. This is particularly useful when events originate from different machines and need some way of synchronizing. > Scenario: Again, consider bid and ask stream… However, bid and ask requests are time-stamped on trader at the time that the order is placed.
  • 31. 7. Application time > Seller places two ask requests respectively at time 8:00:00 and 8:00:12 > Buyer places one bid request at time 8:00:11
  • 32. 7. Application time > Remember that we want to correlate using a 10 seconds window, as anything older is stale… > Hence first event from seller should not be considered, and we should correlate the ask price of 11.0 with the bid price of 9.5
  • 33. 7. Application time > However, the reality is that the first two events could arrive together in a burst in the exchange, and the third could be delayed in the cloud…
  • 34. 7. Application time > In this case, bid price of 9.5 would correlate to ask price of 10.0 and the exchange would loose money as the spread is lower…
  • 35. 7. Application time > Solution: The query does not change… However STREAMS must be configured to use application time-stamps based upon some event property, instead of having events being system-timestamped… BidEventType symbol string customer string bidPrice float orderTime dateTime
  • 36. 8. Missing event detection > Problem: Alert if an expected event is missing after some amount of time. > Scenario: Consider a SALESTREAM stream, containing transaction type (customer order or shipment), and order id. Alert if an order is not followed by a shipment within 10 seconds. 36
  • 37. 8. Missing event detection Time Input Output 1s {1, “ORDER”} 5s {2, “ORDER”} 10s {1, “SHIPMENT”} 10s 15s {3, “ORDER”} 15+t {“DELAYED”, 2} 20s {3, “SHIPMENT”} 37
  • 38. 8. Missing event detection > Solution: SELECT "DELAYED" as alertType, orders.orderId, FROM salestream MATCH_RECOGNIZE ( PARTITION BY orderId MEASURES CustOrder.orderId AS orderId PATTERN (CustOrder NotTheShipment*) DURATION 10 SECONDS DEFINE CustOrder AS (type = ‘ORDER’), NotTheShipment AS ((NOT (eventType = ‘ SHIPMENT’))) ) AS orders
  • 39. Conclusion > Online processing, that is, no need to store to disk first > Declarative approach > Able to deal with unbounded data-sets (streams) > Powerful temporal constructs > Able to find complex relationships using pattern matching > Leverage Relational algebra from DBMS by means of converting STREAM-RELATION and RELATION- STREAM > Rich library of event processing design patterns