Cloud-Ready Web Messaging With CometD by S. Bordet
-
Upload
corley-srl -
Category
Internet
-
view
869 -
download
0
description
Transcript of Cloud-Ready Web Messaging With CometD by S. Bordet
Simone Bordet
Cloud-ReadyWeb Messagging
with CometD
CloudConf – TorinoApril 3rd, 2014
Simone Bordet
Who Am I
Simone Bordet [email protected] @simonebordet
Open Source Contributor Jetty, CometD, MX4J, Foxtrot, LiveTribe, JBoss, Larex
Lead Architect at Intalio/Webtide Jetty's SPDY, FastCGI and HTTP client maintainer
CometD project leader Web messaging framework
Simone Bordet
Agenda
What is CometD ?
CometD Use Cases
CometD Features
Questions & Answers
Simone Bordet
What is CometD
CometD is a web messaging framework Implements a publish/subscribe pattern on the web
Web applications use a request/response paradigm Because historically web applications run over HTTP
CometD uses a messaging paradigm For example: 1 “request” message, 3 “response” messages Server push – no “request”, 1-N “response” messages
Cloud-ready Either stateless or easily clusterable
Simone Bordet
CometD Use Cases
Social Networking Chat and Notifications
Simone Bordet
CometD Use Cases
Online Gaming Not First Person Shooters – yet :)
Simone Bordet
CometD Use Cases
Auctions & Trading Updating bids, prices and availability
Simone Bordet
CometD Use Cases
Systems Monitoring Alerts and System Status
Simone Bordet
CometD Use Cases
Online Collaboration/Productivity Tools
Simone Bordet
Comet Web Applications
A new kind of web applications Server-side event driven Highly dynamic using AJAX / WebSocket on the client
Asynchronous and concurrent by definition
Big impacts on servers Servers must support async I/O
Thread-per-request model does not scale
Servers must support WebSocket With an easy fall-back to HTTP
Simone Bordet
CometD Features
CometD provides libraries Build your own solutions with the CometD libraries No out of the box products
CometD JavaScript Libraries
CometD Java Libraries
Simone Bordet
CometD Performance
CometD Load Test (using a real chat application)
HTTP 20k clients 50k messages/s 200 ms median latency
WebSocket 100k clients 50k messages/s 4 ms median latency
Simone Bordet
CometD Performance
CometD 3 Roughly 25% to 100% better than CometD 2
Depending on the load
CometD 3 based on Servlet 3.1 Ships new HTTP transport based on Servlet 3.1 Async I/O
Jetty 9.1 implements Servlet 3.1 Implementation already very stable
Simone Bordet
CometD Features – JavaScript
require(['dojox/cometd', 'dojo/domReady!'],
function(cometd) {
cometd.init('http://myserver/cometd');
cometd.subscribe('/my/channel', function(message) {
var data = message.data;
// Do something with the data
});
cometd.publish('/my/channel', {
chatText: 'hello!'
});
cometd.disconnect();
});
Simone Bordet
CometD Features – JavaScript
Easy to make Comet “Hello Worlds” Very difficult to make it fail nicely in real scenarios –
CometD does it
Network disconnection detection Applications notified via function callback
Message batching Sending multiple messages to server efficiently
Page reload extension Reload a page in the browser without losing connectivity
Simone Bordet
CometD Features – Server
Spring Framework integration
Confidentiality HTTPS and WSS supported out of the box
Authentication Controlled via SecurityPolicy OAuth integration
Authorization Coarse grained via SecurityPolicy Fine grained via channel Authorizers
Simone Bordet
CometD Features – Server
Transport independence (both client and server) Applications do not hardcode to a specific transport
Lazy messages Deliver non important messages on first occasion Save I/O and CPU when it matters
Acknowledge Extension Provides server-to-client ordering and acknowledgement of
messages
Activity Extension Disconnect idle clients after a period of inactivity
Simone Bordet
CometD Cloud Features
The Cloud:
Dynamic horizontal scaling under load
Various degrees of support for fail-over Almost always requires application support
Applications have to be aware of multiple nodes Data sharing / replication
Simone Bordet
CometD Features – Clustering
Oort CometD's scalability clustering solution
Shards clients among nodes
Not a high availability solution On node failure clients reconnect automatically But may have lost information
Oort cluster members autodiscovery Multicast based Static based on “well known” nodes
Existing nodes forward topology to new nodes
Simone Bordet
CometD Features – Oort
Oort cluster messages auto re-broadcasting For example, chat applications work out of the box
No code needed !
B
A C
Client A Client B Client C
Simone Bordet
CometD Features – Seti
Seti Clustered peer-to-peer communication
Oort performs broadcasting communication
Seti maps a user ID token to a session ID Presence information is broadcasted on the cluster
Each Seti knows the location of all user IDs Efficient peer-to-peer communication
Multiple session IDs for the same user ID For example, connecting from desktop and mobile
Simone Bordet
CometD Features – Seti
B
A C
Client A Client B Client C
Simone Bordet
CometD Features – OortObjects
Distributed OortObjects Distribution of object state across nodes
OortObject<T> A composite, uniquely named, object made of “parts”
Only one “part” is owned by the node, others are read-only
Trades more memory for smaller data access latency
Typical Examples The number of users on each node The list of chat rooms a friend has joined The friends of a friend in a social application
Simone Bordet
CometD Features – OortObjects
A1, A2
B1
NodeA
C1A C2A
users
A1, A2
B1
NodeB
C1B
users
Simone Bordet
CometD Features – OortServices
Distributed OortServices Forwarding of service actions across nodes
OortService<R, C> One uniquely named service in each node Forwards actions to owner node (possibly itself) Trades less memory for higher data access latencies
Typical Examples Precise counters (even unique-across-cluster) Update actions (e.g. chess moves)
Simone Bordet
CometD Features – OortServices
NodeA
P1
game_service
forward(...)
NodeB
P2
game_service
onForward(...)
onForwardSucceeded(...)
Simone Bordet
CometD Features – OortObjects
OortObject and OortService allow sharding Geographical-based, load-based, business-based
Typical examples US users vs EU users Play games locally for better performance
Simone Bordet
References
CometD http://cometd.org http://docs.cometd.org
Jetty http://eclipse.org/jetty
Intalio/Webtide https://webtide.com