views:

364

answers:

4

Hi,

I'm building a chat system for a company and I'm wondering as to what the best way to build the system would be?

The current setup we have is a Nginx HTTP Server with PHP and Memcacheq (as a message queue that appends the chat messages to the user's own queue). We then poll the Nginx server (through a Comet style request) and query the message queue for updates.

Is it a good idea to use a message queue such as Memcacheq to handle a chat system that has both user-to-user and site-wide chat or is it best to just stick to MySQL?

Thanks!

+1  A: 

I would expect Memcacheq to perform much better than MySQL.

Sjoerd
+1  A: 

Memcache is only useful when you have somewhat stale data (or bad database design to increase query execution time). In your case (chat system), the data would be fresh and adding Memcache can only complicate (read decrease performance) things as far as I can see. Think of memcache as a middle ware (on RAM) between mysql and php. If the data is stale the trip time is reduced as PHP does not have to go to mysql but in case of fresh data the load will actually increase (since memcache will also need to fetch the changes from PHP).

In summary, I would not recommend using memcache for a chat system. Would recommend to search the web more. A good post at http://blog.tech.stylefeeder.com/2008/08/22/memcached-vs-mysql/

pinaki
Does it make any difference that I'm using MemcacheQ and not just a regular Memcache setup? I'll take a look at that page now - thanks!
Simon
From what i know, MemcacheQ is just a wrapper over memcache providing queueing capabilities. Should not make any difference.
pinaki
+1  A: 

Memcacheq is a great tool which can help to avoid latency of web requsts. It can act as a buffer between php and mysql, but it's not a replacement of mysql. Memcacheq can also make scaling easier, cause there maybe multiple distributed message consumers.

I'd recommend to put it in between high loaded php requests saving data to mysql and doing time consuming operations. This wil speed up page loading for users and will free your webservers from long requests.

Memcacheq is pretty fast. It will not take much resourses

Andriy Bohdan
The way it currently works is that all the chat messages are archived in a MySQL table but at the point of the message(s) being sent, information regarding the db entry is entered in to a specific Memcache message queue and delivered to the user in near real-time. This seems to be a more efficient approach than constantly polling the database for updates.Thanks for your thoughts by the way!
Simon
A: 

Try this: http://pushmodule.slact.net/ . Nginx will take care of the comet stuff, and all your php application will need to do is send HTTP requests to the module.

slact