views:

208

answers:

2

This is more out of curiosity and "for future reference" than anything, but how is Comet implemented on the database-side? I know most implementations use long-lived HTTP requests to "wait" until data is available, but how is this done on the server-side? How does the web server know when new data is available? Does it constantly poll the database?

+1  A: 

this is very much application dependent. The most likely implementation is some sort of messaging system.

Most likely, your server side code will consist of quite a few parts:

  • a few app servers that hansle incoming requests,
  • a (separate) comet server that deals with all the open connections to clients,
  • the database, and
  • some sort of messaging infrastructure

the last one, the messaging infrastructure is really the key. This provides a way for the app servers to talk to the comet server. So when a request comes in the app server will put a message into the message queue telling the comet server to notify the correct client(s)

How messaging is implemented is, again, very much application dependent. A very simple implementation would just use a database table called messages and poll that.

But depending on the stack you plan on using there should be more sphisticated tools available.

In Rails I'm using Juggernaut which simply listens on some network port. Whenever there is data to send the Rails Application server opens a connection to this juggernaut push server and tells it what to send to the clients.

levinalex
Didn't directly answer my question, but +1 for the description (and also for the link to Juggernaut, since I use Ruby).
musicfreak
+1  A: 

What DB are you using? If it supports triggers, which many RDBMSs do in some shape or form, then you could have the trigger fire an event that actually tells the HTTP request to send out the appropriate response.

Triggers remove the need to poll... polling is generally not the best idea.

PostgreSQL seems to have pretty good support (even PL/Python).

nategood
Thanks, this is exactly what I need! By the way, I use PostgreSQL too. :)
musicfreak