comet: an overview and a new solution called jabbify
DESCRIPTION
Brian Moschel delivered this talk at the JS.Chi() April 2009 meetup. This talk provides an overview of Comet, also known as HTTP Push, covering how it works on the server and client, several implementation options, and using a new Comet API called Jabbify in an interactive demo.TRANSCRIPT
Comet Overview
Brian MoschelJupiter IT
Overview
Why Comet?
Comet Overvie
wJabbify How It
Works Demo Showcase
Why Comet?
• Web 2.0 Trends1. Time Spent on a Page
Why Comet?
• Web 2.0 Trends2. Half life of a Page’s Content
Why Comet?
• Demand for Comet is growing• Desktop apps moving to the web
• Chat• Real time updates• Don’t like to reload
• Ajax:2003::Comet:2009
Uses
• Multi user collaboration apps– Wiki– Presentation
• Communication– Chat
• Preventing stale data– Stock ticker– Social web updates
• Others?
Polling
Comet Long Polling
Server
Client
Server
Client
Are weThere yet? No
Are weThere yet? No
Are weThere yet? No
Wait for data
Polling vs. Comet
Wait for data
How Comet Works: Client Side• Long Poll
– How?• XHR, JSONP, or any transport, with connection held open
– Pro• It works cross browser
– Con• More overhead
• Forever Frame– How?
• Iframe• Multipart XHR
– Pro• Less overhead, quicker responses
– Con• Lack of error handling, not cross browser
Client Side Issues
• Cross Browser– Duh
• 2 Connection Limit– Use wildcard DNS– Xxx.mywebsite.com -> mywebsite.com
• Synchronous request s (for JSONP)– Long poll has to close to allow other requests to
process
How Comet Works: Server Side
• Simultaneous connections– Traditional servers can’t scale– A thread shared multiple connections
• Wake up when you’re ready to send data
How Comet Works: Server Side
• Python– Orbited– Cometd
• Java– Jetty
• Erlang– ErlyComet
• .NET– Lightstreamer
• Service– Jabbify
Server Side Issues
• Scaling– Every user = 1 connection
• Complexity– Threading– Learning Curve
What is Jabbify?
• Comet, simplified• No server• No setup• JavaScript API and GET requests
Why Jabbify?
Simple to use
Scale easily
Rapid setup
Simple to usesynchronized (_continuations) { for(Iterator<Map.Entry <String, ArrayList<Continuation>>> iter = _continuations.entrySet().iterator(); iter.hasNext();){ Map.Entry<String, ArrayList<Continuation>> entry = iter.next(); ArrayList<Continuation> continuations = entry.getValue(); for(Continuation c : continuations){ c.resume(); } }_continuations.clear();}
Jabbify.connect({name: this.username}, this.continue_to('after_connect'))after_connect: function(){ Jabbify.send('vote','submit', {result: this.result})}
vs
Scale easily
• Scaling comet >> Scaling traditional web applications
• Resource intensive• Jabbify is built to scale as usage grows
Rapid Setup<New id="cf" class="org.mortbay.jetty.plus.naming.Resource"> <Arg>jms/connectionFactory</Arg> <Arg> <New class="org.apache.activemq.ActiveMQConnectionFactory"> <Arg>failover:(tcp://localhost:61616)?initialReconnectDelay=20&maxReconnectDelay=900</Arg> </New> </Arg></New>
<script language="javascript" type="text/javascript" src="jabbify.js"></script>
vs
Comet is complex• Client
– Transports (JSONP, Window.name, Flash, XHR, iframe)
• Server– Special server– Setup time– Learning curve
• Scaling– Resource consumption– Threading issues
Jabbify is simple• Client to Client Comet
– JavaScript API• Jabbify.send(“message”,”create”,{message: “hi there”});
• Server to Client Comet– GET requests
• https://jabbify.com/message_push?key=123&type=message...
How It Works
Demo
Take Home Points
Comet is coming
Jabbify = easy Comet
Showcase• Jabbify Simple Chat Client• Keyboard Demo• Chat.unwrongest.com