tags:

views:

95

answers:

2

Hi all, after an entire day of searches, I would to talk about the best solution for an online chat.

This is what I know:

Ajax poll is the old, bandwith consuming, and not scalable way of doing it. It makes a request for new data to the server every X seconds. This implies one database query every X seconds * number_of_connected_users.

Reverse Ajax and one of its application (comet) requires a customized web-server or a dedicated comet server which can handle the number_of_connected_users amount of long-time http connections.

My actual server is: 1 Xeon CPU, 1 GB of RAM and 1 Gb/s of bandwith. The server is a virtual machine (hence highly scalable).

I need a solution that could scale with the server and the future growing user base.

My doubts are:

  • How much the ajax polling method can impact my bandwith usage?

  • In which way can I optimize the ajax polling to make a db query only when necessary?

  • Can the comet server be run in the same machine of the web-server (Apache)?

  • With the comet way, I still need an interval to do the queries on the database and then send the response, so where is the real-time?

  • With my actual server, can the comet way work?

Thank you in advance.

A: 

You should never use polling if you can get away with it. It clogs up resources on both the server and client. The server must make more database requests with polling, more checks to see if data has changed.

The ajax polling method also generates more unneccessary requests. With polling, you use memory and CPU. Comet (if it's done properly) uses only memory.

The comet server can probably not run under Apache. Apache does not seem to be designed for long running requests. I'd recommend implementing your comet server in ruby (using EventMachine) an example, in Python (using Twisted), or in C.

I don't see why you need to have an interval to do database queries. When you make a change, you can just tell your comet server to notify the neccessary users of the change.

Maz
A: 

I'm writing my website in PHP.

So, I need to run a server (like twisted) and write my chat application in python? This app should take care of incoming ajax request and push new data to clients.

If I understand well, this approach doesn't need a database, right?

ILCARTOLAiO
That is correct. The issue with apache is that it doesn't support long-running requests because it follows the paradigm of a thread per request. This will break under more than a few connections.
Maz