Upload
aparna-chaudhary
View
14.575
Download
0
Embed Size (px)
DESCRIPTION
Tech Talk about Esper - Complex Event Processing Engine in Java.Presented at JTeam Tech Meeting by Aparna Chaudhary
Citation preview
JTeamInnovating J2EE Development
EsperT h e P o w e r t o P r e d i c t
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Agenda
• Predictive Business
• Complex Event Processing
• Esper
• Demo
• Questions JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Predictive Business
JTeamInnovating J2EE Development
"In the future, every company must be able to recognize what is coming early enough to take evasive action or steer towards an emerging opportunity."[Frederick W. Smith-CEO FedEx]
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Business Demands
JTeamInnovating J2EE Development
High throughput
Low latency
High AvailabilityComplexity
Insight
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Conventional Models
JTeamInnovating J2EE Development
• RDBMS
• Adds delays into data storage
• Uses Polling Model
• Wasteful Use of Resources
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Conventional Models
JTeamInnovating J2EE Development
• Messaging Systems
• Process Unitary Events
• No Correlation support
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Agenda
• Predictive Business
• Complex Event Processing
• Esper
• Demo
• Questions JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Complex Event Processing
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Concepts - Event
JTeamInnovating J2EE Development
An event is a piece of data that represents that something happened in the real world, or in software system.
e.g. Stock Tick, Weather, UserClick
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Concepts - Complex Event
JTeamInnovating J2EE Development
An event that could only happen when lots of other events happen.
e.g. Housing Price Drop
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Concepts - Event Stream
JTeamInnovating J2EE Development
A linearly ordered (often by time) sequence of events forms Event Stream.
e.g. Click Stream
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Concepts - Event Cloud
JTeamInnovating J2EE Development
A partially ordered set of events form Event Cloud
e.g.
Set of all stock trades for GOOG within a 5 minute time window is an Event Stream. While all Stocks sold in a business day is an Event Cloud.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Concepts - Event Cloud
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
ESP and CEP
JTeamInnovating J2EE Development
Event Stream Processing is focused more on high-speed querying of data in streams of events and applying mathematical algorithms to the event data.
Complex Event Processing includes event data analysis, but places emphasis on patterns of events, and abstracting and simplifying information in the patterns.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Engine
JTeamInnovating J2EE Development
An event processor is an application that performs operations on event objects, including creating, reading, transforming, aggregating, correlating or removing them.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Engine
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Engine Characteristics
JTeamInnovating J2EE Development
1. Keep the data moving
2. Query on streams
3. Handle Stream Imperfections
4. Integrate Stored and Streaming Data
5. Guarantee Data Safety and Availability
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Engine Characteristics
JTeamInnovating J2EE Development
6. Partition and scale applications automatically
7. Process and Respond instantaneously
8. Interoperability
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP in Application Architecture
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Commercial CEP Products
JTeamInnovating J2EE Development
• Weblogic Event Server
• Coral8
• TIBCO
• IBM
• StreamBase
• Progress
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP/EDA and SOA [1/3]
JTeamInnovating J2EE Development
EDA is SOA 2.0
EDA is Proactive SOAEDA and SOA Complementary
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP/EDA and SOA [2/3]
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP/EDA and SOA [3/3]
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Real World Applications
JTeamInnovating J2EE Development
Capital Markets
BAM - Business Activity Monitoring
Supply Chain Management
Flight Operations Monitoring
Fraud Detection
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Agenda
• Predictive Business
• Complex Event Processing
• Esper
• Demo
• Questions JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Esper
JTeamInnovating J2EE Development
• Dual Licensing model
• Open Source GPL
• Esper Tech
• Q2/2007 BEA Partner
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Good Documentation
JTeamInnovating J2EE Development
• Nice reference document
• Patterns catalogue available online
• Lots of examples
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Lightweight
JTeamInnovating J2EE Development
• ANTLR
• CGLIB
• LOG4J
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Ohloh Analysis Summary
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Pluggability
JTeamInnovating J2EE Development
• Works with any Java Process
• OSGI Enabled
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Architecture
JTeamInnovating J2EE Development
ESPER Engine
EPServiceProvider
Event Objects
Listeners
Configuration
EPL Statements JDB
C Adapter
Subscribers
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
API Overview
JTeamInnovating J2EE Development
• EPServiceProvider
• Acts as Engine
• EPStatement
• Queries written in EQL
• UpdateListener
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Event
JTeamInnovating J2EE Development
• POJOs
• Key value pairs (java.util.Map)
• XML Documents
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Event
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Event Properties
JTeamInnovating J2EE Development
Type Syntax Example
Simple name sensor
Indexed name[index] sensor[0]
Mapped name(key) sensor(‘light’)
Nested name.nestedName
sensor.value
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
UpdateListener
JTeamInnovating J2EE Development
Receives updated data as soon as it is processed for the statement.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Subscriber
JTeamInnovating J2EE Development
• Must provide a method by name update to receive insert stream events row-by-row
• The number and types of parameters declared by the update method must match the number and types of columns as specified in the select clause, in the same order as in the select clause
•Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Subscriber
JTeamInnovating J2EE Development
select orderId, price, count(*) from OrderEvent
public class MySubscriber { ...
public void update(String orderId, double price, long count) {...}
}
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Esper Engine Integration
JTeamInnovating J2EE Development
• Obtain an Esper engine instance
• Create a statement (using the Esper query language)
• Register the statement with the engine
• Create a listener (by implementing a Java interface that will be triggered when the statement evaluates to true) and attach it to the statement
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Esper Engine Integration
JTeamInnovating J2EE Development
//Register events Configuration configuration = new Configuration(); configuration.addEventType("TempEvent", BodyTemperatureEvent.class.getName());
// Get Esper CEP Engine
EPServiceProvider cepEngine = EPServiceProviderManager.getProvider("esper-sports-poc", configuration);
// Create EPStatement
PlayerBMIStatement playerBMIStatement = new PlayerBMIStatement(cepEngine.getEPAdministrator());
playerBMIStatement.addListener(new PlayerBMIListener());
// Dispatch Event
cepEngine.getEPRuntime().sendEvent(eventInstance);
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
EPL
JTeamInnovating J2EE Development
Similar to SQL
Name BPRoss 110
Rachel 120Joe 100
Stream
Event
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Sliding Window Support
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Streams
JTeamInnovating J2EE Development
Input stream denotes new events arriving, the term remove stream denotes events leaving a data window.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Windows
JTeamInnovating J2EE Development
• win:length(4)
• win:time(4 sec)
• win:time_batch(4 sec)
• win:length_batch(4)
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Batch Time Window
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Named Windows
JTeamInnovating J2EE Development
• Analogous to database views
• Created using SELECT queries
• Define window (view) first and insert datacreate window OrdersTimeWindow.win:time(30 sec) as select symbol, volume, price from OrderEvent
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Filters
JTeamInnovating J2EE Development
select * from Withdrawal(amount>=200).win:length(5)
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Aggregations
JTeamInnovating J2EE Development
• sum
• avg
• count
• min/max
• stddev
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Output Rate Limiting
JTeamInnovating J2EE Development
Engine dispatches to Listener when output condition occurs.
e.g.select irstream symbol, volume, price from MarketData.win:time(5.5 sec) output every 1 seconds
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Event Patterns
JTeamInnovating J2EE Development
Pattern Expression = Pattern atoms + Pattern Operators
every (spike=ServiceMeasurement(latency>20000) or error=ServiceMeasurement(success=false))
select s from pattern [every s=SubmitOrderEvent -> (timer:interval(30 sec) and not OrderAcceptedEvent(theOrder.id=s.theOrder.id))]
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
RDBMS Integration
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
RDBMS Integration
JTeamInnovating J2EE Development
select name, healthy_temp from TempEvent.win:time(60 sec) temp, sql:mydb3 [' select name,healthy_temp from Player where name = ${temp.playerName} and ${temp.temperature} > healthy_temp ']
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Non Event Based Data Integration
JTeamInnovating J2EE Development
public class InstrumentRepository {
public static Exchange[] getExchangesForSymbol(String symbol) {
...
}
select ord, eligibleExchanges from TheOrder as ord,
method:com.ociweb.jnb.esper.InstrumentRepository.getExchangesForSymbol(ord.symbol) as eligibleExchanges
}
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (1/9)
JTeamInnovating J2EE Development
Filtering:e.g. Click-stream analysis: a filter may be used to capture the trades that originate from a certain set of IP addresses.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (2/9)
JTeamInnovating J2EE Development
In Memory Caching:e.g. Click-stream analysis: a typical application may hold the recent clicks and searches performed by the users, coupled with the relevant historical and reference information.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (3/9)
JTeamInnovating J2EE Development
Aggregation over Windows:e.g. Click-stream analysis: it is often useful to compute the number of visitors who click on a particular link within a specified time interval.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (4/9)
JTeamInnovating J2EE Development
Database Lookups:e.g. Trading: a trading application may look up historical price for a stock, or certain information about an order, or certain rules and regulations stored in a database.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (5/9)
JTeamInnovating J2EE Development
Database Writes:e.g. Click-stream analysis: storing the raw click-stream history, together with derived data, in the database
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (6/9)
JTeamInnovating J2EE Development
Correlation (Joins):e.g. Trading: correlating information from multiple exchanges to find arbitrage opportunities.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (7/9)
JTeamInnovating J2EE Development
Event Pattern Matching:e.g. Fraud detection: fraud patterns are often described as a sequence of events, in one or more streams.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (8/9)
JTeamInnovating J2EE Development
Hierarchical Events:e.g. Order Processing: Purchase Order can have multiple items which needs to be processed differently.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP Design Patterns (9/9)
JTeamInnovating J2EE Development
Dynamic Queries:e.g. Trading environments: every trader can enter their subscriptions like X=MSFT, Y=.1%, Z=10 am.
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
EsperIO
JTeamInnovating J2EE Development
Provides adapters support:
• CSVAdapter
• JMSAdapter
• OpenTick Adapter
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Demo
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Performance Tips
JTeamInnovating J2EE Development
// Better performance
select * from RFIDEvent
// Less good performance
select assetId, zone, xlocation, ylocation from RFIDEvent
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Conclusion
JTeamInnovating J2EE Development
Do I really need it?
Do I have the right infrastructure?
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Conclusion
JTeamInnovating J2EE Development
• Learning Curve of EPL
• No Standardization of EPL
• EPL is still evolving
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Questions?
JTeamInnovating J2EE Development
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
CEP in Dutch Market
JTeamInnovating J2EE Development
• KLM - TIBCO
• Boekhandels Groep Nederlands (BGN)
Wednesday, April 1, 2009
JTeamInnovating J2EE Development
Resources
JTeamInnovating J2EE Development
Esper http://esper.codehaus.org/
CEP
http://complexevents.com/
CEP http://www.cepbusinesscast.com/CEPOpen Source SOA
Wednesday, April 1, 2009