ilcartolaio
ilcartolaio

Reputation: 61

Online chat - Ajax poll or Reverse Ajax

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:

Thank you in advance.

Upvotes: 3

Views: 1294

Answers (2)

ILCARTOLAiO
ILCARTOLAiO

Reputation: 21

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?

Upvotes: 0

Maz
Maz

Reputation: 3375

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.

Upvotes: 1

Related Questions