0
Oracle Coherence and WebLogic
12c
Delivering Real Time Push at
Scale
Steve Millidge
© C2B2 Consulting Limited 2013
All Rig...
About Me
• Founder of C2B2
– Leading Independent Middleware Experts
– Non-functional Experts

• Vendor Neutral
– Red Hat (...
Agenda
•
•
•
•
•
•

Introduction to Web Sockets and Push
WebSockets in WebLogic 12c
Introduction to Coherence
Test Demo
Co...
Standard HTTP model

•Client requests data – server responds

© C2B2 Consulting Limited 2013
All Rights Reserved
The problems with HTTP

•
•
•
•

HTTP is a request-response protocol
HTTP is half-duplex – one way traffic
HTTP is statele...
Push to browser

© C2B2 Consulting Limited 2013
All Rights Reserved
Simulated Push – HTTP Polling
• Regular requests at a set interval
• Near real-time
• Server events may occur between requ...
Simulated Push – Long polling
• Connection is kept open
• Response is blocked until an event occurs or a
timeout occurs
• ...
HTTP Streaming
• Long lived HTTP connection
• Or XMLHttpRequest connection
• Browser needs to close and reconnect the
stre...
Reverse AJAX/Comet
• Utilises long polling or HTTP Streaming techniques
• Complex development
• Poor scalability

© C2B2 C...
The Future - Web Sockets
• New to HTML 5
• Enables Full Duplex communication between a
browser and a Server
• Allows Web S...
Web Socket standards
• This is all in flux
• Rfc 6455 defines the
protocol
• W3C SSE
http://dev.w3.org/html
5/eventsource/...
Browser Support
•
•
•
•
•

Chrome 4+
Internet Explorer 10+
Firefox 4+
Opera 10.7+
Safari 5+

© C2B2 Consulting Limited 201...
Benefits over old techniques
•
•
•
•
•

Reduced latency
Reduced network traffic
Reduced CPU/memory usage on the server
Sca...
Web Socket Protocol
•Client

•Server

•GET /chat HTTP/1.1
•Host: server.example.com
Upgrade: websocket
•Connection: Upgrad...
From the RFC
•Conceptually, WebSocket is really just a layer on top of TCP that
does the following:
• adds a web origin-ba...
JavaScript API
•Web Socket
•WebSocket(location,protocol)
•Function onmessage
•Function onopen
•Function onclose
•Function ...
W3C Definition
[Constructor(in DOMString url, in optional DOMString protocol)]
interface WebSocket {
readonly attribute DO...
WebSockets in WebLogic

© C2B2 Consulting Limited 2013
All Rights Reserved
WebLogic Key Classes
• Note this is only in WebLogic 12c
WebSocketConnection
WebSocket
Listener

WebSocket
Context

WebSoc...
WebLogic Annotations
@WebSocket (
pathPatterns = {"/chat/*"},
dispatchPolicy = "ChatWorkManager",
timeout = 30,
maxConnect...
JSR 356
• @ServerEndpoint(path="/echo")
public class EchoBean {
@OnMessage
public String echo(String message) {
return mes...
Oracle Coherence
Real Time Push @ Scale?

© C2B2 Consulting Limited 2013
All Rights Reserved
JCache
• JCache standard api for caches
• JSR 107 (Coming in JEE7)
• Provides Map Semantics for Cache
– put(Key,Object)
– ...
Data Cache
• Data Caches aren’t New
– Hibernate Session Cache
– Entity Bean Cache
– JPA Cache
– Custom Caches
– Open Sourc...
GET B

PUT C

Cache Partitioning
Application

C
Application

Application

Cache

Cache

Cache

Cache

PUT B

B
Application...
HA Cache Partitioning
Application

Application

Application

Cache

Cache

Cache

Cache

PUT B

B
Application

B

NODE
CRA...
Typical Coherence Grid
Application

Application

Application

Application

Application

Application

Application

Cache

C...
Coherence Partitioned Cache
• Linear Scalability
– 2 hops for Read (Worst Case)
– 2 hops for Write (Worst Case)

• High Av...
Coherence Key Features
• Elasticity
•
Grow and Shrink the Cluster
• Grid Execution
•

•
•
•
•
•

Push code around the clus...
Grid Events Subsystem

Application

Cache
Listener

Application

Application

Application

Cache

Cache

Cache

Cache

© C...
Coherence Event Listeners
• Coherence classes MapEvent, MapListener
• Each time a record is changed, Coherence
raises a Ma...
Events
• E_ALL
– All Events

• E_INSERTED
– Inserts

• E_DELETED
– Deletes

• E_UPDATED
– Updated

• E_UPDATED_LEFT
– Upda...
JSR 107 API
•boolean registerCacheEntryListener(
• CacheEntryListener cacheEntryListener);
•Fired on
• Expired
• Removed
•...
Best Practice Architecture

Load Balancer
JEE
Cluster
Node

JEE
Cluster
Node

JEE
Cluster
Node

JEE
Cluster
Node

JEE
Clus...
Stock Ticker Architecture

WebLogic 12c
Application
Cache

StockTicker App
Application
Cache

© C2B2 Consulting Limited 20...
Demo
http://demo.c2b2.co.uk:7080
Follow the Link

© C2B2 Consulting Limited 2013
All Rights Reserved
Stock Ticker Classes
Ticker
(WebSocket
Adapter)

Stock

Index.jsp

Named
Cache

WAR File

WebLogic 12c
WebSocket
Engine

P...
PushUpdates
public static void main(String args[]) throws Exception {
// attach to Coherence
CacheFactory.ensureCluster();...
Ticker
@WebSocket (
pathPatterns = {"graph/*"},
timeout = 3600
)
public class Ticker extends WebSocketAdapter implements M...
Ticker init
@Override
public void init(WebSocketContext context) {
super.init(context);
CacheFactory.ensureCluster();
cach...
Ticker entryUpdated
public void entryUpdated(MapEvent me) {
// marshall to JSON
Stock stock = (Stock) me.getNewValue();
Ma...
index.jsp
var chart;
document.chart = new Highcharts.Chart({
….
})
websocket.onmessage = function(event) {
var object = JS...
Summary
• Reduced latency, network traffic and
CPU/memory usage on the server
• Highly scalable
• When linked to Coherence...
© C2B2 Consulting Limited 2013
All Rights Reserved
Upcoming SlideShare
Loading in...5
×

Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at Scale

2,726

Published on

Presentation delivered by Steve Millidge at DOAG German Oracle User Group Conference in Nuremberg, 19-21 November 2013.

The real time web is coming with Websockets in HTML 5. The big question is how to deliver event driven architectures for websockets at scale. This session delivered by a member of the JSR 347 Data Grids expert group provides an insight on how combining Oracle Coherence with the new Websockets support in WebLogic 12c can deliver enterprise scale push to web devices. The session first provides an introduction to websockets and delves into typical Oracle Coherence architectures and how they deliver linear scalability and high availability. We then look at the event capabilities inherent in Oracle Coherence that when hooked up to the new WebLogic 12c Web Sockets server can deliver Coherence grid updates in real time to HTML 5 devices.

The presentation will be a mixture of of animated graphical slides depicting how WebLogic Web Sockets and Oracle Coherence work, combined with code snippets. We will then provide a demo hosted on amazon EC2 of the described architecture for delegates to browse to and interact with to show the capabilities of websockets on their devices. Demos will again use Oracle Coherence and WebLogic 12c.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,726
On Slideshare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
46
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at Scale"

  1. 1. Oracle Coherence and WebLogic 12c Delivering Real Time Push at Scale Steve Millidge © C2B2 Consulting Limited 2013 All Rights Reserved
  2. 2. About Me • Founder of C2B2 – Leading Independent Middleware Experts – Non-functional Experts • Vendor Neutral – Red Hat (JBoss), Oracle (Fusion), VMWare (vFabric), Open Source (Apache) • 20 Years Middleware Expertise • 15 years Field Consultancy © C2B2 Consulting Limited 2013 All Rights Reserved
  3. 3. Agenda • • • • • • Introduction to Web Sockets and Push WebSockets in WebLogic 12c Introduction to Coherence Test Demo Code walkthrough - Hooking up to Coherence Summary © C2B2 Consulting Limited 2013 All Rights Reserved
  4. 4. Standard HTTP model •Client requests data – server responds © C2B2 Consulting Limited 2013 All Rights Reserved
  5. 5. The problems with HTTP • • • • HTTP is a request-response protocol HTTP is half-duplex – one way traffic HTTP is stateless – lots of redundant data New connection required for each transaction © C2B2 Consulting Limited 2013 All Rights Reserved
  6. 6. Push to browser © C2B2 Consulting Limited 2013 All Rights Reserved
  7. 7. Simulated Push – HTTP Polling • Regular requests at a set interval • Near real-time • Server events may occur between requests © C2B2 Consulting Limited 2013 All Rights Reserved
  8. 8. Simulated Push – Long polling • Connection is kept open • Response is blocked until an event occurs or a timeout occurs • Resource hungry on the server © C2B2 Consulting Limited 2013 All Rights Reserved
  9. 9. HTTP Streaming • Long lived HTTP connection • Or XMLHttpRequest connection • Browser needs to close and reconnect the streaming channel to release memory © C2B2 Consulting Limited 2013 All Rights Reserved
  10. 10. Reverse AJAX/Comet • Utilises long polling or HTTP Streaming techniques • Complex development • Poor scalability © C2B2 Consulting Limited 2013 All Rights Reserved
  11. 11. The Future - Web Sockets • New to HTML 5 • Enables Full Duplex communication between a browser and a Server • Allows Web Servers to push updates to browsers • Better than “long polling” • Establishes a Dedicated Socket to the Backend Web Socket Server © C2B2 Consulting Limited 2013 All Rights Reserved
  12. 12. Web Socket standards • This is all in flux • Rfc 6455 defines the protocol • W3C SSE http://dev.w3.org/html 5/eventsource/ • W3C WebSockets http://dev.w3.org/html 5/websockets/ © C2B2 Consulting Limited 2013 All Rights Reserved
  13. 13. Browser Support • • • • • Chrome 4+ Internet Explorer 10+ Firefox 4+ Opera 10.7+ Safari 5+ © C2B2 Consulting Limited 2013 All Rights Reserved
  14. 14. Benefits over old techniques • • • • • Reduced latency Reduced network traffic Reduced CPU/memory usage on the server Scalable Simplified development © C2B2 Consulting Limited 2013 All Rights Reserved
  15. 15. Web Socket Protocol •Client •Server •GET /chat HTTP/1.1 •Host: server.example.com Upgrade: websocket •Connection: Upgrade •Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Origin: http://example.com •Sec-WebSocket-Protocol: chat, superchat •Sec-WebSocket-Version: 13 •HTTP/1.1 101 Switching •Protocols Upgrade: websocket Connection: Upgrade Sec-WebSocketAccept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= •Sec-WebSocket-Protocol: chat © C2B2 Consulting Limited 2013 All Rights Reserved
  16. 16. From the RFC •Conceptually, WebSocket is really just a layer on top of TCP that does the following: • adds a web origin-based security model for browsers • adds an addressing and protocol naming mechanism to support multiple services on one port and multiple host names on one IP address • layers a framing mechanism on top of TCP to get back to the IP packet mechanism that TCP is built on, but without length limits • includes an additional closing handshake in-band that is designed to work in the presence of proxies and other intermediaries © C2B2 Consulting Limited 2013 All Rights Reserved
  17. 17. JavaScript API •Web Socket •WebSocket(location,protocol) •Function onmessage •Function onopen •Function onclose •Function onerror •close() •send(data) •Server Sent Events • EventSource(location) •Function onmessage •Function onopen •Function onerror © C2B2 Consulting Limited 2013 All Rights Reserved
  18. 18. W3C Definition [Constructor(in DOMString url, in optional DOMString protocol)] interface WebSocket { readonly attribute DOMString URL; // ready state const unsigned short CONNECTING = 0; const unsigned short OPEN = 1; const unsigned short CLOSED = 2; readonly attribute unsigned short readyState; readonly attribute unsigned long bufferedAmount; // networking attribute Function onopen; attribute Function onmessage; attribute Function onclose; boolean send(in DOMString data); void close(); }; WebSocket implements EventTarget; © C2B2 Consulting Limited 2013 All Rights Reserved
  19. 19. WebSockets in WebLogic © C2B2 Consulting Limited 2013 All Rights Reserved
  20. 20. WebLogic Key Classes • Note this is only in WebLogic 12c WebSocketConnection WebSocket Listener WebSocket Context WebSocketConnection WebSocketConnection © C2B2 Consulting Limited 2013 All Rights Reserved
  21. 21. WebLogic Annotations @WebSocket ( pathPatterns = {"/chat/*"}, dispatchPolicy = "ChatWorkManager", timeout = 30, maxConnections = 1000 ) public class MyListener implements WebSocketListener { ... } © C2B2 Consulting Limited 2013 All Rights Reserved
  22. 22. JSR 356 • @ServerEndpoint(path="/echo") public class EchoBean { @OnMessage public String echo(String message) { return message + " (from your server)"; } } © C2B2 Consulting Limited 2013 All Rights Reserved
  23. 23. Oracle Coherence Real Time Push @ Scale? © C2B2 Consulting Limited 2013 All Rights Reserved
  24. 24. JCache • JCache standard api for caches • JSR 107 (Coming in JEE7) • Provides Map Semantics for Cache – put(Key,Object) – Object get(Key) • Most Caches support this api • Coherence supports the api © C2B2 Consulting Limited 2013 All Rights Reserved
  25. 25. Data Cache • Data Caches aren’t New – Hibernate Session Cache – Entity Bean Cache – JPA Cache – Custom Caches – Open Source Caches • Typically Cache Database Data • Data Grids are Cache on Steroids! © C2B2 Consulting Limited 2013 All Rights Reserved
  26. 26. GET B PUT C Cache Partitioning Application C Application Application Cache Cache Cache Cache PUT B B Application B C B © C2B2 Consulting Limited 2013 All Rights Reserved
  27. 27. HA Cache Partitioning Application Application Application Cache Cache Cache Cache PUT B B Application B NODE CRASH!! ! © C2B2 Consulting Limited 2013 All Rights Reserved
  28. 28. Typical Coherence Grid Application Application Application Application Application Application Application Cache Cache Cache Cache Cache Cache Cache Application Application Application Application Application Application Application Cache Cache Cache Cache Cache Cache Cache Application Application Application Application Application Application Application Cache Cache Cache Cache Cache Cache Cache © C2B2 Consulting Limited 2013 All Rights Reserved
  29. 29. Coherence Partitioned Cache • Linear Scalability – 2 hops for Read (Worst Case) – 2 hops for Write (Worst Case) • High Availability – Configurable Duplicates • Location Independent Access – Grid knows where data is • More Nodes = More Data in Memory © C2B2 Consulting Limited 2013 All Rights Reserved
  30. 30. Coherence Key Features • Elasticity • Grow and Shrink the Cluster • Grid Execution • • • • • • Push code around the cluster Grid Queries Near Cache Continuous Query Cache Many Caching Strategies © C2B2 Consulting Limited 2013 All Rights Reserved
  31. 31. Grid Events Subsystem Application Cache Listener Application Application Application Cache Cache Cache Cache © C2B2 Consulting Limited 2013 All Rights Reserved
  32. 32. Coherence Event Listeners • Coherence classes MapEvent, MapListener • Each time a record is changed, Coherence raises a MapEvent • Override entryUpdated, entryInserted and entryDeleted to process these events • MapListeners can have filters © C2B2 Consulting Limited 2013 All Rights Reserved
  33. 33. Events • E_ALL – All Events • E_INSERTED – Inserts • E_DELETED – Deletes • E_UPDATED – Updated • E_UPDATED_LEFT – Updated and now not matched • E_UPDATED_WITHIN – Updated still matched • E_KEYSET – All updated which change the matching set • E_UPDATED_ENTERED – Updated and now matched © C2B2 Consulting Limited 2013 All Rights Reserved
  34. 34. JSR 107 API •boolean registerCacheEntryListener( • CacheEntryListener cacheEntryListener); •Fired on • Expired • Removed • Updated • Read © C2B2 Consulting Limited 2013 All Rights Reserved
  35. 35. Best Practice Architecture Load Balancer JEE Cluster Node JEE Cluster Node JEE Cluster Node JEE Cluster Node JEE Cluster Node Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion Applicat Cach ion e e e e e e e e e e e e e e e e e e e e e © C2B2 Consulting Limited 2013 All Rights Reserved
  36. 36. Stock Ticker Architecture WebLogic 12c Application Cache StockTicker App Application Cache © C2B2 Consulting Limited 2013 All Rights Reserved
  37. 37. Demo http://demo.c2b2.co.uk:7080 Follow the Link © C2B2 Consulting Limited 2013 All Rights Reserved
  38. 38. Stock Ticker Classes Ticker (WebSocket Adapter) Stock Index.jsp Named Cache WAR File WebLogic 12c WebSocket Engine PushUpdates © C2B2 Consulting Limited 2013 All Rights Reserved
  39. 39. PushUpdates public static void main(String args[]) throws Exception { // attach to Coherence CacheFactory.ensureCluster(); NamedCache cache = CacheFactory.getCache("Stocks"); // create a random stock and stick it in Coherence while(true) { Stock stock = new Stock("C2B2","C2B2",Math.random() * 100.0); cache.put("C2B2", stock); int sleepTime = (int)(500*Math.random() + 500); Thread.currentThread().sleep(sleepTime); } } © C2B2 Consulting Limited 2013 All Rights Reserved
  40. 40. Ticker @WebSocket ( pathPatterns = {"graph/*"}, timeout = 3600 ) public class Ticker extends WebSocketAdapter implements MapListener { public Ticker() { try { jaxb = JAXBContext.newInstance(Stock.class); } catch (JAXBException ex) { Logger.getLogger(Ticker.class.getName()).log(Level.SEVERE, null, ex); } } © C2B2 Consulting Limited 2013 All Rights Reserved
  41. 41. Ticker init @Override public void init(WebSocketContext context) { super.init(context); CacheFactory.ensureCluster(); cache = CacheFactory.getCache("Stocks"); System.out.println("Got Cache " + cache); cache.addMapListener(this); } © C2B2 Consulting Limited 2013 All Rights Reserved
  42. 42. Ticker entryUpdated public void entryUpdated(MapEvent me) { // marshall to JSON Stock stock = (Stock) me.getNewValue(); Marshaller m = jaxb.createMarshaller(); m.setProperty("eclipselink.media-type", "application/json"); StringWriter sw = new StringWriter(30); m.marshal(stock, sw); // now write to socket Set<WebSocketConnection> conns = getWebSocketContext().getWebSocketConnections(); for (WebSocketConnection conn : conns) { conn.send(sw.toString()); } } © C2B2 Consulting Limited 2013 All Rights Reserved
  43. 43. index.jsp var chart; document.chart = new Highcharts.Chart({ …. }) websocket.onmessage = function(event) { var object = JSON.parse(event.data); var x = (new Date()).getTime(); var y = object.price; document.chart.series[0].addPoint([x,y],true,true,false); } © C2B2 Consulting Limited 2013 All Rights Reserved
  44. 44. Summary • Reduced latency, network traffic and CPU/memory usage on the server • Highly scalable • When linked to Coherence, provide enterprise scale, event driven, real time push © C2B2 Consulting Limited 2013 All Rights Reserved
  45. 45. © C2B2 Consulting Limited 2013 All Rights Reserved
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×