Top Banner
WSO2 Complex Event Processor Sriskandarajah Suhothayan (Suho) Srinath Perera WSO2 Inc.
68

WSO2 Complex Event Processor

Aug 11, 2014

Download

Data & Analytics

At WSO2Con 2014 Europe
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: WSO2 Complex Event Processor

WSO2 Complex Event Processor

Sriskandarajah Suhothayan (Suho)Srinath Perera

WSO2 Inc.

Page 2: WSO2 Complex Event Processor

Outline

• BigData• Complex Event Processing• Basic Constructs of Query Language • CEP Solution Patterns• Scale, HA and Performance • Demo

Page 3: WSO2 Complex Event Processor
Page 4: WSO2 Complex Event Processor
Page 5: WSO2 Complex Event Processor
Page 6: WSO2 Complex Event Processor

Why Big Data is hard?• How store? Assuming 1TB bytes it takes 1000

computers to store a 1PB • How to move? Assuming 10Gb network, it

takes 2 hours to copy 1TB, or 83 days to copy a 1PB

• How to search? Assuming each record is 1KB and one machine can process 1000 records per sec, it needs 277CPU days to process a 1TB and 785 CPU years to process a 1 PB

• How to process? – How to convert algorithms to work in large size

– How to create new algorithms

http://www.susanica.com/photo/9

Page 7: WSO2 Complex Event Processor

Why it is hard (Contd.)?•System build of many computers •That handles lots of data•Running complex logic •This pushes us to frontier of Distributed Systems and Databases

•More data does not mean there is a simple model

•Some models can be complex as the system

http://www.flickr.com/photos/mariachily/5250487136, Licensed CC

Page 8: WSO2 Complex Event Processor

Big data Processing Technologies Landscape

Page 9: WSO2 Complex Event Processor

WSO2 Bigdata Offerings

Page 10: WSO2 Complex Event Processor

Scenarios of Event Processing

Months

Days

hours

Minutes

Seconds

100 ms

< 1ms

0 10 100 1000 10000 100000 ~1M

Aggregate Data Rate (Events/seconds)

Late

ncy

Relational Database Applications Operational Analytics

Applications

Monitoring Applications Financial Trading

Applications

ManufacturingApplications

Data Warehousing Applications

Web Analytics Applications

CEP Target Scenarios

Page 11: WSO2 Complex Event Processor

CEP Is & Is NOT!

• Is NOT!• Simple filters

• Simple Event Processing• E.g. Is this a gold or platinum customer?

• Joining multiple event streams• Event Stream Processing

• Is !• Processing multiple event streams • Identify meaningful patterns among streams• Using temporal windows

• E.g. Notify if there is a 10% increase in overall trading activity AND the average price of commodities has fallen 2% in the last 4 hours

Page 12: WSO2 Complex Event Processor

What is ?

Page 13: WSO2 Complex Event Processor

Query Functions of CEP

• Filter • Transformation • Window + { Aggregation, group by }• Join • Event Sequence • Event Table

Page 14: WSO2 Complex Event Processor

CEP Architecture

Page 15: WSO2 Complex Event Processor

Event Streams

• Event stream is a sequence of events • Event streams are defined by Stream Definitions• Events streams have in-flows and out-flows

• Inflows can be from• Event builders

Converts incoming XML, JSON, etc events to event stream

• Execution plans• Outflows are to

• Event formattersConverts to event stream to XML, JSON, etc events

• Execution plans

Page 16: WSO2 Complex Event Processor

Stream Definition {

'name':'phone.retail.shop', 'version':'1.0.0', 'nickName': 'Phone_Retail_Shop', 'description': 'Phone Sales', 'metaData':[ {'name':'clientType','type':'STRING'} ], 'correlaitonData':[ {'name':’transactionID’,'type':'STRING'} ], 'payloadData':[ {'name':'brand','type':'STRING'}, {'name':'quantity','type':'INT'}, {'name':'total','type':'INT'}, {'name':'user','type':'STRING'} ]}

Page 17: WSO2 Complex Event Processor

Event Format

• Standard event formats are available for • XML• JSON• Text• Map• WSO2 Event

• If events adhere to the standard format they do not need data mapping.

• If events do not adhere custom event mapping should be configured in Event builder & Event Formatter appropriately.

Page 18: WSO2 Complex Event Processor

Event Format

Standard XML event format

<events> <event> <metaData> <tenant_id>2</tenant_id> </metaData> <correlationData> <activity_id>ID5</activity_id> </correlationData> <payloadData> <clientPhoneNo>0771117673</clientPhoneNo> <clientName>Mohanadarshan</clientName> <clientResidenceAddress>15, Alexendra road,

California</clientResidenceAddress> <clientAccountNo>ACT5673</clientAccountNo> </payloadData> </event><events>

Page 19: WSO2 Complex Event Processor

CEP Execution Plan

● Is an isolated logical execution unit

● Each execution plan imports some of the event streams available in CEP and defines the execution logic using queries and exports the results as output event streams.

● Has one-to-one relationship with CEP Backend Runtime.

● Has many-to-many relationship with Event Streams.

● Each execution plan spawns a Siddhi Engine Instance.

Page 20: WSO2 Complex Event Processor

CEP Solution patterns

1. Transformation - project, translate, enrich, split2. Filter3. Composition / Aggregation / Analytics

● basic stats, group by, moving averages

4. Join multiple streams 5. Detect patterns

● Coordinating events over time ● Trends - increasing, decreasing, stable, non-increasing, non-decreasing,

mixed

6. Blacklisting 7. Building a profile

Page 21: WSO2 Complex Event Processor

Siddhi Query Structure

define stream <event stream>(<attribute> <type>,<attribute> <type>, ...);

from <event stream>select <attribute>,<attribute>, ...insert into <event stream> ;

Page 22: WSO2 Complex Event Processor

Siddhi Query : Projection

define stream TempStream(deviceID long, roomNo int, temp double);

from TempStreamselect roomNo, tempinsert into OutputStream ;

Page 23: WSO2 Complex Event Processor

Siddhi Query : Inferred Streams

from TempStreamselect roomNo, tempinsert into OutputStream ;

define stream OutputStream(roomNo int, temp double);

Page 24: WSO2 Complex Event Processor

Siddhi Query : Enrich

from TempStreamselect roomNo, temp,‘C’ as scaleinsert into OutputStream

define stream OutputStream(roomNo int, temp double, scale string);

Page 25: WSO2 Complex Event Processor

Siddhi Query : Enrich

from TempStreamselect deviceID, roomNo, avg(temp) as avgTempinsert into OutputStream ;

Page 26: WSO2 Complex Event Processor

Siddhi Query : Transformation

from cseEventStream[price >= 20 and symbol==’IBM’]select symbol, volumeinsert into StockQuote

from TempStreamselect concat(deviceID, ‘-’, roomNo) as uid,

toFahrenheit(temp) as tempInF, ‘F’ as scale

insert into OutputStream ;

Page 27: WSO2 Complex Event Processor

Siddhi Query : Split

from TempStreamselect roomNo, tempinsert into RoomTempStream ;

from TempStreamselect deviceID, tempinsert into DeviceTempStream ;

Page 28: WSO2 Complex Event Processor

Siddhi Query : Filter

from TempStream [temp > 30.0 and roomNo != 2043]select roomNo, tempinsert into HotRoomsStream ;

Page 29: WSO2 Complex Event Processor

Siddhi Query : Window

from TempStreamselect roomNo, avg(temp) as avgTempinsert into HotRoomsStream ;

Page 30: WSO2 Complex Event Processor

Siddhi Query : Window

from TempStream#window.time(1 min)select roomNo, avg(temp) as avgTempinsert into HotRoomsStream ;

Page 31: WSO2 Complex Event Processor

Siddhi Query : Window

from TempStream#window.time(1 min)select roomNo, avg(temp) as avgTempgroup by roomNoinsert into HotRoomsStream ;

Page 32: WSO2 Complex Event Processor

Siddhi Query : Batch Window

from TempStream#window.timeBatch(5 min)select roomNo, avg(temp) as avgTempgroup by roomNoinsert into HotRoomsStream ;

Page 33: WSO2 Complex Event Processor

Siddhi Query : Joindefine stream TempStream

(deviceID long, roomNo int, temp double);

define stream RegulatorStream(deviceID long, roomNo int, isOn bool);

Page 34: WSO2 Complex Event Processor

Siddhi Query : Joindefine stream TempStream

(deviceID long, roomNo int, temp double);

define stream RegulatorStream(deviceID long, roomNo int, isOn bool);

from TempStream[temp > 30.0]#window.time(1 min) as T join RegulatorStream[isOn == false]#window.lenght(1) as R on T.roomNo == R.roomNoselect T.roomNo, R.deviceID, ‘start’ as actioninsert into RegulatorActionStream ;

Page 35: WSO2 Complex Event Processor

Siddhi Query : Detect Trend

from t1=TempStream, t2=TempStream [t1.temp < t2.temp and t1.deviceID == t2.deviceID]+

within 5 minselect t1.temp as initialTemp, t2.temp as finalTemp, t1.deviceID, t1.roomNo insert into IncreaingHotRoomsStream ;

Page 36: WSO2 Complex Event Processor

Siddhi Query : Partition

define partition Device by TempStream.deviceID ;

define partition Temp by range TempStream.temp <= 0 as ‘ICE’, range TempStream.temp > 0 and

TempStream.temp < 100 as ‘WATER’, range TempStream.temp > 100 as ‘VAPOUR’ ;

Page 37: WSO2 Complex Event Processor

Siddhi Query : Detect Trend per Partition

define partition Device by TempStream.deviceID ;

from t1=TempStream, t2=TempStream [t1.temp < t2.temp and t1.deviceID == t2.deviceID]+

within 5 minselect t1.temp as initialTemp, t2.temp as finalTemp, t1.deviceID, t1.roomNo insert into IncreaingHotRoomsStream partition by Device ;

Page 38: WSO2 Complex Event Processor

Siddhi Query : Detect Pattern

define stream Purchase (price double, cardNo long,place string);

from every (a1 = Purchase[price < 10] -> a3= ..) -> a2 = Purchase[price >10000 and a1.cardNo == a2.cardNo]

within 1 dayselect a1.cardNo as cardNo, a2.price as price, a2.place as placeinsert into PotentialFraud ;

Page 39: WSO2 Complex Event Processor

Siddhi Query : Define Event Table

define table CardUserTable (name string, cardNum long) ;

define table CardUserTable (name string, cardNum long) from (‘datasource.name’=‘CardDataSource’, ‘table.name’=‘UserTable’, ‘caching.algorithm’=‘LRU’) ;

Cache types supported● Basic: A size-based algorithm based on FIFO.● LRU (Least Recently Used): The least recently used event is dropped

when cache is full.● LFU (Least Frequently Used): The least frequently used event is dropped

when cache is full.

Page 40: WSO2 Complex Event Processor

Siddhi Query : Query Event Table

define stream Purchase (price double, cardNo long, place string);

define table CardUserTable (name string, cardNum long) ;

from Purchase#window.length(1) join CardUserTableon Purchase.cardNo == CardUserTable.cardNum

select Purchase.cardNo as cardNo, CardUserTable.name as name, Purchase.price as price

insert into PurchaseUserStream ;

Page 41: WSO2 Complex Event Processor

Siddhi Query : Insert into Event Table

define stream FraudStream (price double, cardNo long, userName string);

define table BlacklistedUserTable (name string, cardNum long) ;

from FraudStreamselect userName as name, cardNo as cardNuminsert into BlacklistedUserTable ;

Page 42: WSO2 Complex Event Processor

Siddhi Query : Update into Event Table

define stream LoginStream (userID string, islogin bool, loginTime long);

define table LastLoginTable (userID string, time long) ;

from LoginStreamselect userID, loginTime as timeupdate LastLoginTable

on LoginStream.userID == LastLoginTable.userID ;

Page 43: WSO2 Complex Event Processor

Siddhi Extensions

● Function extension● Aggregator extension● Window extension● Transform extension

Page 44: WSO2 Complex Event Processor

Siddhi Query : Function Extension

from TempStreamselect deviceID, roomNo,

custom:toKelvin(temp) as tempInKelvin, ‘K’ as scale

insert into OutputStream ;

Page 45: WSO2 Complex Event Processor

Siddhi Query : Aggregator Extension

from TempStreamselect deviceID, roomNo, temp

custom:stdev(temp) as stdevTemp, ‘C’ as scale

insert into OutputStream ;

Page 46: WSO2 Complex Event Processor

Siddhi Query : Window Extension

from TempStream#window.custom:lastUnique(roomNo,2 min)

select *insert into OutputStream ;

Page 47: WSO2 Complex Event Processor

Siddhi Query : Transform Extension

from XYZSpeedStream#transform.custom:getVelocityVector(v,vx,vy,vz)

select velocity, directioninsert into SpeedStream ;

Page 48: WSO2 Complex Event Processor

CEP Event Adaptors

● For receiving and publishing events● Has the configurations to connect to external endpoints● Has many-to-one relationship with Event Streams

Page 49: WSO2 Complex Event Processor

CEP Event Adaptors

Support for several transports (network access)● SOAP● HTTP● JMS● SMTP● SMS● Thrift● Kafka

Supporting data formats ● XML● JSON● Map● Text● WSO2Event - WSO2 data format over Thrift for High Performant Event transfer

supporting Java/C/C++/C# via Thrift language bindings

Page 50: WSO2 Complex Event Processor

CEP Event Adaptors

Supports database writes using Map messages● Cassandra ● MYSQL ● H2

Supports custom event adaptors via its pluggable architecture!

Page 51: WSO2 Complex Event Processor

Monitoring & Debugging : Event Flow

● Visualization of the Event Stream flow in CEP● Helps to get the big picture ● Good for debugging

Page 52: WSO2 Complex Event Processor

Monitoring & Debugging : Event Tracer

• Dump message traces in a textual format • Before and after processing each stage of event flow

Page 53: WSO2 Complex Event Processor

Monitoring & Debugging : Event Statistics

• Real-time statistics• via visual illustrations & JMX • Time based request & response counts • Stats on all components of CEP server

Page 54: WSO2 Complex Event Processor

Real Time Dashboard

• Provides tools to configure gadgets• Currently supports RDBMS only

• Powered by WSO2 User Engagement Server ( WSO2UES)

Page 55: WSO2 Complex Event Processor

• Same JVM Performance (Siddhi with Esper, M means a Million) 4 core machine

• Filters 8M Events/Sec vs Esper 2M • Window 2.5M Events/Sec vs. Esper 1M• Patterns 1.4M Events/Sec about 10X faster than Esper

• Over the Network Performance (Using thrift based WSO2 event format) - 8 core machine• Filter 0.25M (or 250K) Event/Sec

Performance Results

Page 56: WSO2 Complex Event Processor

CEP High Availability

Execution plan in “RedundantNode” based distributed processing mode

<executionPlan name="RedundantNodeExecutionPlan" statistics="enable" trace="enable" xmlns="http://wso2.org/carbon/eventprocessor"> ... <siddhiConfiguration> <property name="siddhi.enable.distributed.processing">RedundantNode</property> <property name="siddhi.persistence.snapshot.time.interval.minutes">0</property> </siddhiConfiguration> ...</executionPlan>

Page 57: WSO2 Complex Event Processor

HA / Persistence

• Option 1: Side by side • Recommended• Takes 2X hardware• Gives zero down time

• Option 2: Snapshot and restore• Uses less HW • Will lose events between snapshots• Downtime while recovery • ** Some scenarios you can use event tables to keep

intermediate state

Page 58: WSO2 Complex Event Processor

Scaling

• Vertically scaling• Can be distributed as a pipeline

• Horizontally scaling• Queries like windows, patterns, and Join have shared states• Hard to distribute!

Page 59: WSO2 Complex Event Processor

Scaling (Contd.)

• Currently users have to setup the pipeline manually (WSO2 team can help)

• Work is underway to support above pipeline and distributer operators out of the box

Page 60: WSO2 Complex Event Processor

Lambda Architecture

Page 61: WSO2 Complex Event Processor
Page 62: WSO2 Complex Event Processor

Demo

Page 63: WSO2 Complex Event Processor

Scenario

MyPizzaShop – On time delivery or free Pizza Offer !!!

Page 64: WSO2 Complex Event Processor

Order Event

{ "event": { "correlationData": { "orderNo": "0023" }, "payloadData": { "orderInfo": "2 L PEPPERONI", "amount": "25.70", "name": "James Mark", "address": "29BX Finchwood Ave, Clovis, CA 93611", "tpNo": "(626)446-4601" } }}

Page 65: WSO2 Complex Event Processor

Delivered to customer event

correlation_orderNo:23,isDelivered:true

Page 66: WSO2 Complex Event Processor

Email Notification

Hi Alis Miranda

Your order for 1 L CHICKEN pizza will be delivered in 30 mins to779 Burl Ave, Clovis, CA 93611.

The total cost of the order is $14.5.If you didn't get the pizza within 30 min you will be eligible to have those pizzas for

free..!!

MyPizzaShop

Page 67: WSO2 Complex Event Processor

Final Payment Notification

<event xmlns="http://wso2.org/carbon/event"> <correlationData> <orderNo>3</orderNo> </correlationData> <payloadData> <name>James Clark</name> <amount>54.0</amount> </payloadData> </event>

Page 68: WSO2 Complex Event Processor

Thank You