Mehdi Karamnejad
Mehdi Karamnejad

Reputation: 175

Ajax vs Comet (not a chat application)

I've developed a web-based application in which a signed in user should send a message to the server telling he is still online every 3 seconds. The message is then processed by the server and a stored procedure is called in Mysql to set the user's status to online. I've looked in to similar issues in which Comet and Ajax are compared (here or here) but considering that 3 second delay is acceptable and maximum users of 1000 are online in the system, is using Ajax a wise choice or Comet should be used?

Upvotes: 2

Views: 954

Answers (2)

J.C. Yamokoski
J.C. Yamokoski

Reputation: 1014

In this particular case, since you do not need to send any information from the server to the client(s), I believe Ajax is the more appropriate solution. Every three seconds, the client tells the server it is connected, the database is updated, and you're done.

It could certainly be done using Comet, in which case you would basically ping each registered client to see if it is still connected. But, you would still need to run a query on the database for each client that responds, plus you would still need the client to notify the server on its initial connection. So, it seems to me that Comet would be more trouble than it's worth. The only thing that might make sense is if you could ping each registered client and store the responses in memory, then once all clients have been pinged you can run one single query to update all of their statuses. This would give you the added bonus of knowing as soon as a client disconnects as opposed to waiting for a timeout. Unfortunately, that is beyond the scope of my expertise with Comet so, at this point, I can't help to actually implement it.

Upvotes: 0

Krilivye
Krilivye

Reputation: 557

For this kind of feature comet is more appropriate:

  • Your clients send messages (i'm online)
  • Your server broadcast the processed message (user X is still online)

In an ajax way you are only serving messages to server.

In order to get the "broadcast effect" in an ajax way. You will end up doing something similar to comet but with less efficient bandwidth.

Ajax:

  • Client send server - i'm in
  • Server process
  • Server send back to client list of user in.

In this case every client ask every 3 second the database for the COMPLETE "in" list.

In comet:

  • Client X send server - i'm in
  • Server process
  • Server send back to client S that user X is still online

In this case every client tell the server every 3 second that he is in. The server send back to every connected client ONLY that x is still in

Comet is just the technique to broadcast back and push messages to client Ajax is the technique to push client information to the server without having to refresh all the page.

Quoting wikipedia: http://en.wikipedia.org/wiki/Comet_%28programming%29

Comet is known by several other names, including Ajax Push, Reverse Ajax , Two-way-web, HTTP Streaming,and HTTP server push among others.

So go comet :)

If you do not broadcast anything, then simple Ajax is the best option

Upvotes: 1

Related Questions