TurnKey Linux Virtual Appliance Library

Using Comet to update web application data in real time?

Recently I've been looking into a powerful but complex web application technology we're considering using in future versions of the Hub.

The problem: how do we update a browser view when a background process updates the database?

A few examples of places in the Hub where this comes up...

  • User launches server, waits for the server to get an IP, for the status icon to change color, etc.
  • User associates a server with an elastic IP
  • User attaches an EBS or detaches an EBS
  • The instance cache expires after N minutes, a background process reloads the information, which is different from the previously displayed information.

You can use "plain old" AJAX polling every N seconds (and most sites with "real-time" data do), but there are a couple of limitations:

  1. Will never be real-time
  2. It can be tricky to scale

Wouldn't it be neat if instead of polling, any changes to database state could be PUSHED on the fly to the browser without any action on the part of the user?

Well it turns out you can do exactly that via a technique called "reverse AJAX" or "Comet" that uses long waiting requests from the client to the server to make sure there is a connection that's always on and ready to accept "pushed" updates from the server.

But since you don't want to dedicate a synchronous process to every waiting poll, it's best to leverage specially designed server software to help you with that.

Currently Comet is mostly being used for chat-like applications (e.g., GTalk, Meebo, Facebook chat) and seems to add considerable complexity (even more than regular AJAX) so I'm not sure it would be a good idea to use this for something as simple as updating a server view but that depends on implementation details so I wouldn't rule it out off the bat.

Comet is just an umbrella term for this type of technique. The actual protocol used in the implementation is typically STOMP, a messaging protocol supported by RabbitMQ (and many others).

Note that there are many excellent open source components that can be leveraged to implement Comet applications:

  • Orbited: an asynchronous COMET server in Python
  • js.io: client-side STOMP client

Further reading

You can get future posts delivered by email or good old-fashioned RSS.
TurnKey also has a presence on Google+, Twitter and Facebook.

Comments

Chris Musty's picture

Real Software Use a Similar Feature

Real Software (Not free by any means - www.realsoftware.com) is a fairly good IDE for makig cross platform applications and have recently released their web edition to make desktop like apps in a browser. Its not quite at a point where I would use it commercially (some bugs etc) but they do use the push methods explained above.

The reson I bring this up is that with my playing around with their web edition for about 3 months now, the loading mouse icon never disappears and causes some real annoyance with end users. It sounds trivial but they believe they are downloading viruses or their connection is not working...

Is this a problem with Comet too? 

Chris Musty

Director

Specialised Technologies

Liraz Siri's picture

Comet is a technique, not a specific piece of software

Comet is an umbrella name for a family of techniques that involve having the web browser use Javascript to make requests (e.g., http://example.com/update) in the background that are intentionally not answered by the web server until the web server wants to "push" something to the client. In other words, it's a trick used to achieve server->client style communication over the regular client->server protocols. Traditional web servers choke when you have too many open connections, hence the need for special software and techniques. But it's not a specific piece of software.

I'm not sure regarding the mouse pointer issue. I can see how leaving requests hanging indefinitely might confuse some browsers into thinking the page is still "loading". OTOH, if I'm not mistaken it should be possible to use CSS3 to override the default mouse pointers.

Comet = Shaveet in He :-)

Django implementation for Comet (by Uriel Katz): https://github.com/urielka/shaveet

Liraz Siri's picture

Sweet! Alon will love this

Thanks for the link Emanuel. This might be just what we were looking for.

Comet alternative

Sorry for the very late reply - I'm new to the Turnkey Linux idea and site and have been reading through the old blog posts here.

Another alternative to Comet that might be useful is http://socket.io/.

It enables realtime communication using many different adaptations including long polling.  We're experimenting with it here and it seems rather useful.

Just another avenue to explore and further muddy the waters.  LOL!

Scott

P.S. - You've got quite a platform developed here.  I'll be another paying customer here within the next couple of days.  Good work!

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)