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).
Polling suffers from latency, event chunking, unnecessary bandwidth use, and connection overhead.
Comet work will touch the entire stack; browser, server, message broker/protocol/models.
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:
- Long-Polling:
- Simplest, just hold open connection and then respond. 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, Response.
- Forever Frame
- iframe points to a chunked resource that flushes occasionally. Fast.
- 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 future.
- Sockets:
- Straight TCP via plugin like Flash, Silverlight. Optimal speed but plugins may choke on lots of data.
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 proxy/firewall troubles.
Real trouble is just that the community is young and fragmented and the whole thing is sort of a hack.
Q&A:
Security is especially young, mostly it’s your app’s problem.
Vendors promise 10k-100k idle connections per server, but big grain of salt.