Tuesday, September 05, 2006

Server sent events

Came across a post on Opera Web Applications Team blog saying Opera will soon support Server Sent Events. Basically, you embed a special HTML element into your document containing an event source URL, and then the browser opens a persistent HTTP connection to it and have the server stream events to it over it and interpret the events as commands for transforming the DOM tree of the document.

This looks like the formalization of an early rudimentary form of AJAX (not called that then, of course) that I stumbled across about four years ago, where they had a page with two frames, one for the content, and another 0-pixel wide one where the server kept streaming an endless HTML page with JavaScript commands that the browser executed in chunks as it received them and thus manipulated the DOM tree of the page in the other frame.

It sounds like a nice thing, with only a single worrisome bit - it doesn't scale. It'll definitely be nice for intranet applications, but I just can't imagine a web application on the Internet based on this technology that can serve several thousands of clients, because that means thousands of open persistent HTTP connections at once. It may work if you code your server using non-blocking IO instead of the traditional one-thread-per-connection model, but I have the feeling sooner or later you'll hit a resource limit, i.e. run out of file descriptors as the number of persistent connections goes up. Right, this can be a concern with ordinary HTTP as well, but at least there connections are usually short and not kept open while idle. On the (yet an)other hand, it might still beat the current AJAX technique of periodically polling the server for events - depends on the frequency of polls, I guess.

Anyway - seems like yet another Web 2.0 feature to keep an eye on.

3 comments:

Anonymous said...

GMail’s GTalk integration and Meebo doesn't poll the server as well. Do they use this JavaScript pushing technique too?

Attila Szegedi said...

For all I know, they could. The trick with a sequence of JavaScript commands being streamed to a hidden frame is several years old, with additional advantage that you don't need to have a browser support for this (very young and very in-progress, shall we say) specification in order for it to work.

Anonymous said...

Server-sent events provide a nice standardization for Comet. Ideally, that standard should be available across all RIA technologies (i.e. JS, Flex, Silverlight, etc.). Luckily, Kaazing Gateway (http://www.kaazing.org) provides a server to scale server-sent events (as well as websockets). It also provides an emulation layer that does not require a plugin that can be used to adapt any browser to consume server-sent events.