views:

240

answers:

1

I want to make it that one user on the site can chat request another user on my Django site. I want the requestee to get a realtime box that say: "Do you want to chat?"

How does the following client polling approach sound:

user1 clicks on users2 nickname, generating a POST request to some /message/requests, which creates a Message of type CHAT_REQUEST in the database. Meanwhile, a Javascript piece at user2's browser, repeatedly queries the server for message updates. When it receives a Message of type CHAT_REQUEST it opens a popup...

The problem with this approach seems to be the database access.

If the client is polling every 10 seconds, and 100 users leave their browser windows open, that is 10 database requests per seconds.

Would it be better to store these messages not in the database, but in Django RAM or session information? Or will this database table be cached in RAM with PostgreSQL, and the retrieval fast?

+3  A: 

A database table for this would put a load on your server, as you said, but might be useful if you want to keep a record of these requests for whatever reason.

Using something like memcached or an AMQP server might give you better performance. If you like you could even use a higher-performance key-value-store such as Tokyo Cabinet / Tokyo Tyrant.

Josh Lindsey