views:

100

answers:

3

I have created a blogging system with php+postgresql. Now I want to add a web chat ( in REAL TIME for Million of users simultaneously ) where every message is saved in database.

I am thinking to use Erlang+Mnesia on a different webserver for this issue.

Message's table will be like this:

message_id, user_id, message, date

user_id should be related with users table in Postgresql database in another webserver.

How can I do that without lose performance ?

If you have any other creative solutions tell me please ;).

+1  A: 

I'm not sure why you want to save every single message in a database, but mnesia doesn't sound like a particularly good choice for doing that. Mnesia is more of a distributed key-value store, that you can use to keep the state of your application, when you need to store "tabular data" and query it, in a simple to medium-complex fashion.

For large amounts of text, I've heard lucene is supposed to be good, it has fulltext search features etc. which are said to be efficient, you might want to look into it:

Apache Lucene Project page

Other than that, using erlang as chatserver, using mnesia to hold all the other state sounds like a good idea, You could write a javascript client that uses something like JSONP (to overcome the cross-domaine-issue) and mochiweb on the erlang site to do the webserver part.

Writing the rest of the core chat system should be fairly simple, the fun part, so to say :)

Amadiro
I wouldn't say that mnesia is a bad fit for this necessarily. It depends on whether he needs full text search or not. Querying over the messages table as he's described it is very doable quite easily in mnesia and a full relational database is overkill for his needs.Lucene doesn't implement the storage it just provides an indexing service for that storage. He would still need a datastore to keep it in.
Jeremy Wall
Well, it sounds like he wants to store massive amounts of data, and mnesia wouldn't be a very good fit for that, but yes, it's doable. But as you said, it kinda depends on in what fashion exactly he wants to use the stored data.
Amadiro
A: 

Mnesia can certainly do what you suggest but if you've already got postgres set up is there some reason you don't want to use that? It might be simpler than creating a whole seperate service and if you want erlang to run the chat service then it has postgres drivers.

Jeremy Wall
If I use postgresql on erlang webserver then how can I relate user_id of message's table with user's table ?
xRobot
I meant using the same database for each. The erlang webserver can talk to the postgres database on a different server.
Jeremy Wall
A: 

This project is using postgresql with great success.

http://zotonic.com/

You may want to use the same code for db access to postgresql.

Flinkman