SlideShare a Scribd company logo
1 of 52
Download to read offline
Time for Comet?
                            Simon Willison
                            Yahoo! Web Development Summit
                            5th December 2007




Header image: http://svn.xantus.org/shortbus/trunk/cometd-perl/html/
A new name for a very
    old technique
Alex Russell coins “Comet”
Deliberately named after a kitchen cleaner
“
Fundamentally, [Comet applications] all
 use long-lived HTTP connections to
    reduce the latency with which
messages are passed to the server. In
 essence, they do not poll the server
occasionally. Instead the server has an
  open line of communication with
which it can push data to the client.
Who’s using it?
More Ajax
                  Time spent on
                   a single page




Less Ajax




            (Slides courtesy of Joe Walker)
Long time
to change


                      Time before a
                      page changes




Short time
to change




             (Slides courtesy of Joe Walker)
Time spent on
More Ajax
                   a single page



                            Time before a
                            page changes



Less Ajax




            (Slides courtesy of Joe Walker)
Early Comet
Netscape 1.1, March 1995
Netscape 1.1 new features

• Tables
• Background images
• “Dynamic Documents”
 • Client Pull
 • Server Push
• This predates JavaScript by an entire year
Server Push, Client Pull
“Client Pull”


<META HTTP-EQUIV=quot;Refreshquot; CONTENT=1>
“Server Push”
Content-type: multipart/x-mixed-replace;boundary=XXooXX

--XXooXX
Content-type: text/plain

Data for the first object.

--XXooXX
Content-type: text/plain

Data for the second and last object.

--XXooXX--
multipart/x-mixed-replace
still works today!
http://zesty.ca/chat/ (1999)
Modern Comet
WARNING


Excessive browser hacks
       coming up
We need a solution that...

• Works through proxies
• Doesn’t “click”
• Doesn’t throb
• Let’s us detect a lost connection
• Works in every browser
Three principle techniques

• Regular polling
• Streaming
 • XMLHttpRequest
 • Forever frame
• Long polling
Streaming XHR
•   Good browsers let you open up a permanent
    XHR request
    •   onreadystatechange is called periodically
    •   If readyState == 3, data has arrived
•   Need to split data on a delimiter and keep
    track of how many delimiters have been seen
•   But... IE won’t let you read responseText until
    the document has completely loaded!
Forever frame
• A hack that takes advantage of progressive
  rendering
• Send <script> blocks down the wire one at
  a time in to an iframe
  • Pad them with enough junk in between to
    clear the buffer in Safari
• Refresh the iframe occasionally to clean up
Killing the throbber
• Streaming techniques cause Firefox to
  continue to display the loading bar
• If you create an empty iframe and add and
  remove it from the DOM when an event is
  received, that problem goes away
  if (load_kill_ifr === null) {
    load_kill_ifr = document.createElement('iframe');
    hide_iframe(load_kill_ifr);
  }
  document.body.appendChild(load_kill_ifr);
  document.body.removeChild(load_kill_ifr);
Forever frame in IE
• Regular forever frame throbs, and causes
  “clicks” in IE when the iframe is refreshed...
• ... unless you embed the iframe in an
  ActiveXObject(quot;htmlfilequot;) (!)
  var htmlfile = new ActiveXObject('htmlfile');
  htmlfile.open();
  htmlfile.write('<html><script>' +
                 'document.domain=quot;' + document.domain + 'quot;;' +
                 '</script></html>');
  htmlfile.parentWindow.Orbited = this; htmlfile.close();
  var iframe_div = htmlfile.createElement('div');
  htmlfile.body.appendChild(iframe_div);
  iframe_div.innerHTML = '<iframe src=quot;' + this.url + 'quot;></iframe>';
htmlfile issues
•   htmlfile gets upset if you try to perform too
    many DOM manipulations from inside it

    •   This appears to relate to JavaScript garbage
        collection

•   One solution is using a queue to shuttle
    messages between htmlfile and the real page

•   Another is to use an empty setInterval() to move
    the DOM manipulations to another thread
Confuse IE with enough nested
 iframes and it forgets to click


                  Huh?
Cross-domain Comet

• The 2 connection limit, combined with the
  need to run a specialist server stack, means
  it’s extremely useful to be able to run your
  Comet server on a separate domain
• This requires even more hacks...
Double iframes
• To do streaming cross-domain in Safari and
  Firefox you need to use iframes to work
  around the same-domain policy
• This causes unwanted history entries
• If you nest two iframes you can navigate the
  inner iframe without affecting browser
  history
Long polling
• The most effective method for punching
  through proxies
• You make a request (via iframe or XHR), the
  server hangs until an event occurs, then it
  sends a response and your client instantly
  reconnects
• Can be scary for broadcast: 10,000 clients all
  re-connecting at the same time
Enough hacks yet?
• http://meteorserver.org/browser-techniques/
• http://cometdaily.com/2007/10/25/http-
  streaming-and-internet-explorer/
• http://cometdaily.com/2007/11/18/ie-
  activexhtmlfile-transport-part-ii/
• http://orbited.org/svn/orbit/trunk/daemon/
  orbited/static/orbited.js
HTML 5
http://www.whatwg.org/specs/web-apps/current-work/#event-source
<event-source src=quot;/cometquot;>

<script type=quot;text/javascriptquot;>
document.getElementsByTagName(quot;event-sourcequot;)[0]
        .addEventListener(quot;server-timequot;, function(event) {
            alert(event.data);
        }, false);
</script>

Content-Type: application/x-dom-event-stream

Event: server-time
data: [time on the server]


Support added in Opera 9.5
“Wow, client-side
   Comet sucks”...
that’s not the half of it
Scaling the server
  http://flickr.com/photos/adrianblack/254968866/ craig1black
• Comet requires potentially tens of
  thousands of simultaneous HTTP
  connections

• Apache and other mainstream servers are
  designed to handle a single request as
  quickly as possible

  • Requests are generally served by a worker
    process or thread

• This absolutely will not scale to Comet
Event-based IO

•   Rather than a thread or process per
    connection, have one process that loops
    through hundreds of connections checking if
    any of them are ready to send or receive data
•   This approach scales, and can even be
    implemented in high level scripting languages
    (such as Perl, Python and Ruby)
Bayeaux
Bayeaux
•   Bayeaux is a protocol for Comet

•   Any Bayeaux client can talk to any Bayeaux server

•   The protocol is based on clients publishing and
    subscribing to channels

•   Data is encoded using JSON

•   Clients can create a permanent connection using a
    handshake, or send simple one-off messages
Dumb Comet servers
• The principle advantage of Bayeaux is that
  your Comet server can be stupid - it
  doesn’t need any application logic, it just
  needs to route messages around
  • It’s a black box which you simply drop in
    to your architecture
• This means your application logic can stay on
  your favourite platform
Cometd
• Cometd (Comet Daemon) is an umbrella
  project for a number of Bayeaux
  implementations
 • cometd-python (in Twisted)
 • cometd-perl (also a Perlbal plugin)
 • cometd-java (on Jetty)
 • dojox.cometd (JavaScript client)
• http://cometd.com/
Still to solve...

• There’s no clear standard method for
  implementing authentication against Bayeaux
  servers
• There’s a need for a way to authorise
  specific clients to post messages on specific
  channels
Related Comet projects
• Meteor - Perl Comet server
 • http://meteorserver.org/
• Orbited - Python Event Daemon
 • http://orbited.org/
• Lightstreamer - commercial Comet server
 • http://www.lightstreamer.com/
So despite all of that...
 Comet applications
  are easy to build
How to build a Comet
application (in 5 minutes)
Set up Jetty

•   Download and unzip Jetty-6.1 from www.mortbay.org

•   Install Maven from http://maven.apache.org/

•   cd jetty-6.1.6/contrib/cometd/demo/

•   mvn jetty:run

•   Browse to http://localhost:8080/

•   Mess around with the JS in src/main/webapp/examples/
dojox.cometd
dojo.addOnLoad(function() {
    dojox.cometd.init(quot;http://127.0.0.1:8080/cometdquot;);
    dojox.cometd.subscribe(quot;/mychannelquot;, function(comet) {
        alert(comet.data); // a JSON object
    });

      dojo.byId('send').onclick = function() {
          dojox.cometd.publish(quot;/mychannelquot;, {
              'msg': quot;A message sent by Cometquot;
          });
          return false;
      };
});
dojox.cometd
dojo.addOnLoad(function() {
    dojox.cometd.init(quot;http://127.0.0.1:8080/cometdquot;);
    dojox.cometd.subscribe(quot;/mychannelquot;, function(comet) {
        alert(comet.data); // a JSON object
    });

      dojo.byId('send').onclick = function() {
          dojox.cometd.publish(quot;/mychannelquot;, {
              'msg': quot;A message sent by Cometquot;
          });
          return false;
      };
});
Here’s my slideshow code

<script type=quot;text/javascriptquot;>
dojo.require(quot;dojox.cometdquot;);
jQuery(function($) {
    dojox.cometd.init(quot;http://127.0.0.1:8080/cometdquot;);
    dojox.cometd.subscribe(quot;/slideshow/changequot;, function(comet) {
        $('#currentSlide').attr('src', comet.data.src);
    });
});
</script>
Conclusions
• Comet requires hacks, but they’re
  reasonably well understood
• Bayeaux and Cometd abstract away the
  nastiness and make Comet accessible to
  sane developers
• If we survived CSS, Comet should be a cinch
• We’re going to see a lot more sites built
  with Comet over the next year
Thank you

More Related Content

What's hot

Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSocketsGunnar Hillert
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)Ericom Software
 
Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015Fastly
 
0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-ServicesIlya Grigorik
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comRuby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comIlya Grigorik
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsSergi Almar i Graupera
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with javaJeongHun Byeon
 
Building Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSocketsBuilding Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSocketsBen Limmer
 
Enhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketEnhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketMauricio "Maltron" Leal
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serializationGWTcon
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ilya Grigorik
 
vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets PresentationVolodymyr Lavrynovych
 
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSocketsJosh Glover
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Arun Gupta
 
Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011David Troy
 
0-60 with Goliath: High performance web services
0-60 with Goliath: High performance web services0-60 with Goliath: High performance web services
0-60 with Goliath: High performance web servicesIlya Grigorik
 
Stupid Boot Tricks: using ipxe and chef to get to boot management bliss
Stupid Boot Tricks: using ipxe and chef to get to boot management blissStupid Boot Tricks: using ipxe and chef to get to boot management bliss
Stupid Boot Tricks: using ipxe and chef to get to boot management blissmacslide
 

What's hot (20)

Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSockets
 
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
WebSockets Everywhere: the Future Transport Protocol for Everything (Almost)
 
Intro to WebSockets
Intro to WebSocketsIntro to WebSockets
Intro to WebSockets
 
Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015
 
0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comRuby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSockets
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
Building Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSocketsBuilding Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSockets
 
Enhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocketEnhancing Mobile User Experience with WebSocket
Enhancing Mobile User Experience with WebSocket
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
 
vlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentationvlavrynovych - WebSockets Presentation
vlavrynovych - WebSockets Presentation
 
Unity and WebSockets
Unity and WebSocketsUnity and WebSockets
Unity and WebSockets
 
Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014Nuts and Bolts of WebSocket Devoxx 2014
Nuts and Bolts of WebSocket Devoxx 2014
 
Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011Servers with Event Machine - David Troy - RailsConf 2011
Servers with Event Machine - David Troy - RailsConf 2011
 
Reverse Ajax
Reverse AjaxReverse Ajax
Reverse Ajax
 
0-60 with Goliath: High performance web services
0-60 with Goliath: High performance web services0-60 with Goliath: High performance web services
0-60 with Goliath: High performance web services
 
Php push notifications
Php push notificationsPhp push notifications
Php push notifications
 
Stupid Boot Tricks: using ipxe and chef to get to boot management bliss
Stupid Boot Tricks: using ipxe and chef to get to boot management blissStupid Boot Tricks: using ipxe and chef to get to boot management bliss
Stupid Boot Tricks: using ipxe and chef to get to boot management bliss
 

Viewers also liked

Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with CometSimon Willison
 
Commet Assay
Commet AssayCommet Assay
Commet AssayUlaa Iman
 
Comets, Asteroids, And Meteors
Comets, Asteroids, And MeteorsComets, Asteroids, And Meteors
Comets, Asteroids, And MeteorsTeach5ch
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8amix3k
 
Asteroids, comets, meteors, and moons
Asteroids, comets, meteors, and moonsAsteroids, comets, meteors, and moons
Asteroids, comets, meteors, and moonspirates71
 
Comets, asteroids & meteors
Comets, asteroids & meteorsComets, asteroids & meteors
Comets, asteroids & meteorsMarni Bunda
 
How To Create Presentation Slides That Are Out Of This World by @slidecomet @...
How To Create Presentation Slides That Are Out Of This World by @slidecomet @...How To Create Presentation Slides That Are Out Of This World by @slidecomet @...
How To Create Presentation Slides That Are Out Of This World by @slidecomet @...HighSpark | Visual Storytelling Agency
 

Viewers also liked (11)

Going Live! with Comet
Going Live! with CometGoing Live! with Comet
Going Live! with Comet
 
Commet Assay
Commet AssayCommet Assay
Commet Assay
 
Comet assay
Comet assayComet assay
Comet assay
 
Comets, Asteroids, And Meteors
Comets, Asteroids, And MeteorsComets, Asteroids, And Meteors
Comets, Asteroids, And Meteors
 
Comets
CometsComets
Comets
 
Comet with node.js and V8
Comet with node.js and V8Comet with node.js and V8
Comet with node.js and V8
 
Comets
CometsComets
Comets
 
Asteroids, comets, meteors, and moons
Asteroids, comets, meteors, and moonsAsteroids, comets, meteors, and moons
Asteroids, comets, meteors, and moons
 
Comets, asteroids & meteors
Comets, asteroids & meteorsComets, asteroids & meteors
Comets, asteroids & meteors
 
How To Create Presentation Slides That Are Out Of This World by @slidecomet @...
How To Create Presentation Slides That Are Out Of This World by @slidecomet @...How To Create Presentation Slides That Are Out Of This World by @slidecomet @...
How To Create Presentation Slides That Are Out Of This World by @slidecomet @...
 
The Greatest Of All Time - 10 Quotes from Muhammad Ali
The Greatest Of All Time - 10 Quotes from Muhammad AliThe Greatest Of All Time - 10 Quotes from Muhammad Ali
The Greatest Of All Time - 10 Quotes from Muhammad Ali
 

Similar to Time for Comet?

IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008Association Paris-Web
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Asher Martin
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008Joe Walker
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologiesgeorge.james
 
Comet: Making The Web a 2-Way Medium
Comet: Making The Web a 2-Way MediumComet: Making The Web a 2-Way Medium
Comet: Making The Web a 2-Way MediumJoe Walker
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享Chia Wei Tsai
 
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoTWebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoTFrank Greco
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebJames Rakich
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSocketsGonzalo Ayuso
 
Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!jfarcand
 
Ajax World Comet Talk
Ajax World Comet TalkAjax World Comet Talk
Ajax World Comet Talkrajivmordani
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax Wrajivmordani
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesSimon Willison
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineRicardo Silva
 
Toster - Understanding the Rails Web Model and Scalability Options
Toster - Understanding the Rails Web Model and Scalability OptionsToster - Understanding the Rails Web Model and Scalability Options
Toster - Understanding the Rails Web Model and Scalability OptionsFabio Akita
 
Understanding the Rails web model and scalability options
Understanding the Rails web model and scalability optionsUnderstanding the Rails web model and scalability options
Understanding the Rails web model and scalability options.toster
 

Similar to Time for Comet? (20)

IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
IE 8 et les standards du Web - Chris Wilson - Paris Web 2008
 
Grizzly Comet Aquarium Paris
Grizzly Comet Aquarium ParisGrizzly Comet Aquarium Paris
Grizzly Comet Aquarium Paris
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
 
Comet from JavaOne 2008
Comet from JavaOne 2008Comet from JavaOne 2008
Comet from JavaOne 2008
 
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar TechnologiesRob Tweed :: Ajax and the Impact on Caché and Similar Technologies
Rob Tweed :: Ajax and the Impact on Caché and Similar Technologies
 
Comet: Making The Web a 2-Way Medium
Comet: Making The Web a 2-Way MediumComet: Making The Web a 2-Way Medium
Comet: Making The Web a 2-Way Medium
 
KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享KSDG-iSlide App 開發心得分享
KSDG-iSlide App 開發心得分享
 
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoTWebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
WebSocket Perspectives 2015 - Clouds, Streams, Microservices and WoT
 
20090315 Comet
20090315 Comet20090315 Comet
20090315 Comet
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the Web
 
Nodejs and WebSockets
Nodejs and WebSocketsNodejs and WebSockets
Nodejs and WebSockets
 
Grizzly 20080925 V2
Grizzly 20080925 V2Grizzly 20080925 V2
Grizzly 20080925 V2
 
Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!
 
Ajax World Comet Talk
Ajax World Comet TalkAjax World Comet Talk
Ajax World Comet Talk
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
 
ICEfaces and JSF 2.0 on GlassFish
ICEfaces and JSF 2.0 on GlassFishICEfaces and JSF 2.0 on GlassFish
ICEfaces and JSF 2.0 on GlassFish
 
Toster - Understanding the Rails Web Model and Scalability Options
Toster - Understanding the Rails Web Model and Scalability OptionsToster - Understanding the Rails Web Model and Scalability Options
Toster - Understanding the Rails Web Model and Scalability Options
 
Understanding the Rails web model and scalability options
Understanding the Rails web model and scalability optionsUnderstanding the Rails web model and scalability options
Understanding the Rails web model and scalability options
 

More from Simon Willison

Cheap tricks for startups
Cheap tricks for startupsCheap tricks for startups
Cheap tricks for startupsSimon Willison
 
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)Simon Willison
 
How we bootstrapped Lanyrd using Twitter's social graph
How we bootstrapped Lanyrd using Twitter's social graphHow we bootstrapped Lanyrd using Twitter's social graph
How we bootstrapped Lanyrd using Twitter's social graphSimon Willison
 
Web Services for Fun and Profit
Web Services for Fun and ProfitWeb Services for Fun and Profit
Web Services for Fun and ProfitSimon Willison
 
Tricks & challenges developing a large Django application
Tricks & challenges developing a large Django applicationTricks & challenges developing a large Django application
Tricks & challenges developing a large Django applicationSimon Willison
 
Advanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
Advanced Aspects of the Django Ecosystem: Haystack, Celery & FabricAdvanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
Advanced Aspects of the Django Ecosystem: Haystack, Celery & FabricSimon Willison
 
How Lanyrd uses Twitter
How Lanyrd uses TwitterHow Lanyrd uses Twitter
How Lanyrd uses TwitterSimon Willison
 
Building Things Fast - and getting approval
Building Things Fast - and getting approvalBuilding Things Fast - and getting approval
Building Things Fast - and getting approvalSimon Willison
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesSimon Willison
 
Building crowdsourcing applications
Building crowdsourcing applicationsBuilding crowdsourcing applications
Building crowdsourcing applicationsSimon Willison
 
Evented I/O based web servers, explained using bunnies
Evented I/O based web servers, explained using bunniesEvented I/O based web servers, explained using bunnies
Evented I/O based web servers, explained using bunniesSimon Willison
 
Cowboy development with Django
Cowboy development with DjangoCowboy development with Django
Cowboy development with DjangoSimon Willison
 
Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with DjangoSimon Willison
 
Class-based views with Django
Class-based views with DjangoClass-based views with Django
Class-based views with DjangoSimon Willison
 
Web App Security Horror Stories
Web App Security Horror StoriesWeb App Security Horror Stories
Web App Security Horror StoriesSimon Willison
 
Web Security Horror Stories
Web Security Horror StoriesWeb Security Horror Stories
Web Security Horror StoriesSimon Willison
 

More from Simon Willison (20)

How Lanyrd does Geo
How Lanyrd does GeoHow Lanyrd does Geo
How Lanyrd does Geo
 
Cheap tricks for startups
Cheap tricks for startupsCheap tricks for startups
Cheap tricks for startups
 
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
 
Building Lanyrd
Building LanyrdBuilding Lanyrd
Building Lanyrd
 
How we bootstrapped Lanyrd using Twitter's social graph
How we bootstrapped Lanyrd using Twitter's social graphHow we bootstrapped Lanyrd using Twitter's social graph
How we bootstrapped Lanyrd using Twitter's social graph
 
Web Services for Fun and Profit
Web Services for Fun and ProfitWeb Services for Fun and Profit
Web Services for Fun and Profit
 
Tricks & challenges developing a large Django application
Tricks & challenges developing a large Django applicationTricks & challenges developing a large Django application
Tricks & challenges developing a large Django application
 
Advanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
Advanced Aspects of the Django Ecosystem: Haystack, Celery & FabricAdvanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
Advanced Aspects of the Django Ecosystem: Haystack, Celery & Fabric
 
How Lanyrd uses Twitter
How Lanyrd uses TwitterHow Lanyrd uses Twitter
How Lanyrd uses Twitter
 
ScaleFail
ScaleFailScaleFail
ScaleFail
 
Building Things Fast - and getting approval
Building Things Fast - and getting approvalBuilding Things Fast - and getting approval
Building Things Fast - and getting approval
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The Libraries
 
Building crowdsourcing applications
Building crowdsourcing applicationsBuilding crowdsourcing applications
Building crowdsourcing applications
 
Evented I/O based web servers, explained using bunnies
Evented I/O based web servers, explained using bunniesEvented I/O based web servers, explained using bunnies
Evented I/O based web servers, explained using bunnies
 
Cowboy development with Django
Cowboy development with DjangoCowboy development with Django
Cowboy development with Django
 
Crowdsourcing with Django
Crowdsourcing with DjangoCrowdsourcing with Django
Crowdsourcing with Django
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Class-based views with Django
Class-based views with DjangoClass-based views with Django
Class-based views with Django
 
Web App Security Horror Stories
Web App Security Horror StoriesWeb App Security Horror Stories
Web App Security Horror Stories
 
Web Security Horror Stories
Web Security Horror StoriesWeb Security Horror Stories
Web Security Horror Stories
 

Recently uploaded

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 

Recently uploaded (20)

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 

Time for Comet?

  • 1. Time for Comet? Simon Willison Yahoo! Web Development Summit 5th December 2007 Header image: http://svn.xantus.org/shortbus/trunk/cometd-perl/html/
  • 2. A new name for a very old technique
  • 3. Alex Russell coins “Comet”
  • 4. Deliberately named after a kitchen cleaner
  • 5. “ Fundamentally, [Comet applications] all use long-lived HTTP connections to reduce the latency with which messages are passed to the server. In essence, they do not poll the server occasionally. Instead the server has an open line of communication with which it can push data to the client.
  • 7.
  • 8. More Ajax Time spent on a single page Less Ajax (Slides courtesy of Joe Walker)
  • 9. Long time to change Time before a page changes Short time to change (Slides courtesy of Joe Walker)
  • 10. Time spent on More Ajax a single page Time before a page changes Less Ajax (Slides courtesy of Joe Walker)
  • 12.
  • 14. Netscape 1.1 new features • Tables • Background images • “Dynamic Documents” • Client Pull • Server Push • This predates JavaScript by an entire year
  • 17. “Server Push” Content-type: multipart/x-mixed-replace;boundary=XXooXX --XXooXX Content-type: text/plain Data for the first object. --XXooXX Content-type: text/plain Data for the second and last object. --XXooXX--
  • 22. We need a solution that... • Works through proxies • Doesn’t “click” • Doesn’t throb • Let’s us detect a lost connection • Works in every browser
  • 23. Three principle techniques • Regular polling • Streaming • XMLHttpRequest • Forever frame • Long polling
  • 24. Streaming XHR • Good browsers let you open up a permanent XHR request • onreadystatechange is called periodically • If readyState == 3, data has arrived • Need to split data on a delimiter and keep track of how many delimiters have been seen • But... IE won’t let you read responseText until the document has completely loaded!
  • 25. Forever frame • A hack that takes advantage of progressive rendering • Send <script> blocks down the wire one at a time in to an iframe • Pad them with enough junk in between to clear the buffer in Safari • Refresh the iframe occasionally to clean up
  • 26. Killing the throbber • Streaming techniques cause Firefox to continue to display the loading bar • If you create an empty iframe and add and remove it from the DOM when an event is received, that problem goes away if (load_kill_ifr === null) { load_kill_ifr = document.createElement('iframe'); hide_iframe(load_kill_ifr); } document.body.appendChild(load_kill_ifr); document.body.removeChild(load_kill_ifr);
  • 27. Forever frame in IE • Regular forever frame throbs, and causes “clicks” in IE when the iframe is refreshed... • ... unless you embed the iframe in an ActiveXObject(quot;htmlfilequot;) (!) var htmlfile = new ActiveXObject('htmlfile'); htmlfile.open(); htmlfile.write('<html><script>' + 'document.domain=quot;' + document.domain + 'quot;;' + '</script></html>'); htmlfile.parentWindow.Orbited = this; htmlfile.close(); var iframe_div = htmlfile.createElement('div'); htmlfile.body.appendChild(iframe_div); iframe_div.innerHTML = '<iframe src=quot;' + this.url + 'quot;></iframe>';
  • 28. htmlfile issues • htmlfile gets upset if you try to perform too many DOM manipulations from inside it • This appears to relate to JavaScript garbage collection • One solution is using a queue to shuttle messages between htmlfile and the real page • Another is to use an empty setInterval() to move the DOM manipulations to another thread
  • 29. Confuse IE with enough nested iframes and it forgets to click Huh?
  • 30. Cross-domain Comet • The 2 connection limit, combined with the need to run a specialist server stack, means it’s extremely useful to be able to run your Comet server on a separate domain • This requires even more hacks...
  • 31. Double iframes • To do streaming cross-domain in Safari and Firefox you need to use iframes to work around the same-domain policy • This causes unwanted history entries • If you nest two iframes you can navigate the inner iframe without affecting browser history
  • 32. Long polling • The most effective method for punching through proxies • You make a request (via iframe or XHR), the server hangs until an event occurs, then it sends a response and your client instantly reconnects • Can be scary for broadcast: 10,000 clients all re-connecting at the same time
  • 33. Enough hacks yet? • http://meteorserver.org/browser-techniques/ • http://cometdaily.com/2007/10/25/http- streaming-and-internet-explorer/ • http://cometdaily.com/2007/11/18/ie- activexhtmlfile-transport-part-ii/ • http://orbited.org/svn/orbit/trunk/daemon/ orbited/static/orbited.js
  • 34. HTML 5 http://www.whatwg.org/specs/web-apps/current-work/#event-source <event-source src=quot;/cometquot;> <script type=quot;text/javascriptquot;> document.getElementsByTagName(quot;event-sourcequot;)[0] .addEventListener(quot;server-timequot;, function(event) { alert(event.data); }, false); </script> Content-Type: application/x-dom-event-stream Event: server-time data: [time on the server] Support added in Opera 9.5
  • 35. “Wow, client-side Comet sucks”... that’s not the half of it
  • 36. Scaling the server http://flickr.com/photos/adrianblack/254968866/ craig1black
  • 37. • Comet requires potentially tens of thousands of simultaneous HTTP connections • Apache and other mainstream servers are designed to handle a single request as quickly as possible • Requests are generally served by a worker process or thread • This absolutely will not scale to Comet
  • 38. Event-based IO • Rather than a thread or process per connection, have one process that loops through hundreds of connections checking if any of them are ready to send or receive data • This approach scales, and can even be implemented in high level scripting languages (such as Perl, Python and Ruby)
  • 40. Bayeaux • Bayeaux is a protocol for Comet • Any Bayeaux client can talk to any Bayeaux server • The protocol is based on clients publishing and subscribing to channels • Data is encoded using JSON • Clients can create a permanent connection using a handshake, or send simple one-off messages
  • 41. Dumb Comet servers • The principle advantage of Bayeaux is that your Comet server can be stupid - it doesn’t need any application logic, it just needs to route messages around • It’s a black box which you simply drop in to your architecture • This means your application logic can stay on your favourite platform
  • 42. Cometd • Cometd (Comet Daemon) is an umbrella project for a number of Bayeaux implementations • cometd-python (in Twisted) • cometd-perl (also a Perlbal plugin) • cometd-java (on Jetty) • dojox.cometd (JavaScript client) • http://cometd.com/
  • 43. Still to solve... • There’s no clear standard method for implementing authentication against Bayeaux servers • There’s a need for a way to authorise specific clients to post messages on specific channels
  • 44. Related Comet projects • Meteor - Perl Comet server • http://meteorserver.org/ • Orbited - Python Event Daemon • http://orbited.org/ • Lightstreamer - commercial Comet server • http://www.lightstreamer.com/
  • 45. So despite all of that... Comet applications are easy to build
  • 46. How to build a Comet application (in 5 minutes)
  • 47. Set up Jetty • Download and unzip Jetty-6.1 from www.mortbay.org • Install Maven from http://maven.apache.org/ • cd jetty-6.1.6/contrib/cometd/demo/ • mvn jetty:run • Browse to http://localhost:8080/ • Mess around with the JS in src/main/webapp/examples/
  • 48. dojox.cometd dojo.addOnLoad(function() { dojox.cometd.init(quot;http://127.0.0.1:8080/cometdquot;); dojox.cometd.subscribe(quot;/mychannelquot;, function(comet) { alert(comet.data); // a JSON object }); dojo.byId('send').onclick = function() { dojox.cometd.publish(quot;/mychannelquot;, { 'msg': quot;A message sent by Cometquot; }); return false; }; });
  • 49. dojox.cometd dojo.addOnLoad(function() { dojox.cometd.init(quot;http://127.0.0.1:8080/cometdquot;); dojox.cometd.subscribe(quot;/mychannelquot;, function(comet) { alert(comet.data); // a JSON object }); dojo.byId('send').onclick = function() { dojox.cometd.publish(quot;/mychannelquot;, { 'msg': quot;A message sent by Cometquot; }); return false; }; });
  • 50. Here’s my slideshow code <script type=quot;text/javascriptquot;> dojo.require(quot;dojox.cometdquot;); jQuery(function($) { dojox.cometd.init(quot;http://127.0.0.1:8080/cometdquot;); dojox.cometd.subscribe(quot;/slideshow/changequot;, function(comet) { $('#currentSlide').attr('src', comet.data.src); }); }); </script>
  • 51. Conclusions • Comet requires hacks, but they’re reasonably well understood • Bayeaux and Cometd abstract away the nastiness and make Comet accessible to sane developers • If we survived CSS, Comet should be a cinch • We’re going to see a lot more sites built with Comet over the next year