Developer Day Notes 2: Give Your Sites a Push with Comet
by Dan Drinkard
Goals: What is it, how does it, how do I, the future?
In short, a method to push to browser instead of client pull (eg.
Polling suffers from latency, event chunking, unnecessary bandwidth use,
and connection overhead.
Comet work will touch the entire stack; browser, server, message
Bayeux is sort of synonymous with Comet for many people. It’s a Dojo
Foundation project for solving common Comet problems, basically a set of
protocols (content encoding, formatting, API, no guarantees, etc.).
ome folks use XMPp, nice and robust and stable.
Stomp, Streaming Text-Oriented Messaging Protocol has some fans. Looks
sort of like HTTP.
Message Brokers take info from messaging layer to app, Apache ActiveMQ
(v popular), RabbitMQ (Java/.Net/C#), MorbidQ (good for testing).
Transports – last mile to browser:
- Simplest, just hold open connection and
- Forever Frame
- iframe points to a chunked resource that flushes
- XHR Streaming:
- Same thing but with XHR, fire OnreadyStateChange but
[maybe] only WebKit supports it.
- ActiveX htmlfile,
- IE-only so… booooo.
- Server-Sent Events:
- HTML 5 spec so of course Opera only. Maybe cool in
- Straight TCP via plugin like Flash, Silverlight. Optimal
speed but plugins may choke on lots of data.
Client retries on timeout. Looks like only good for one event. “3x max
latency” – worst case if you just miss an event is: Response, Request,
Problems: 2-connection limit, same-origin policy, still half-duplex
because HTTP fundamentally is.
Example: what are Twitter users listening to now?
Server: Orbited, built on Py/Twisted with Ruby and PHP APIs. Easy to
set up, socket-like interface.
Real easy install and short config.
[Code looks sort of Rails-like in that it gives you places to drop
your poller, display code, etc. and you fill them in. Nice.]
Trouble with eating RAM and connections, and possible you’ll have
Real trouble is just that the community is young and fragmented and the
whole thing is sort of a hack.
Security is especially young, mostly it’s your app’s problem.
Vendors promise 10k-100k idle connections per server, but big grain of