[erlang-questions] Distributed comms and Mnesia

Lee Sylvester lee.sylvester@REDACTED
Wed Apr 3 10:08:26 CEST 2013


Hey guys,

So, based on my posts yesterday; I would like my websocket platform to be distributed.  To help with this, I figured I'd use Mnesia.  I can opt for the "in memory" option, as if a node goes down, the connections will be lost, anyway.  Using Mnesia, I can tag users with their pid, so I can message them directly rather than sending messages to every node, whether or not a recipient exists there.

Okay, so that's the theory out the door.  Now for the impl.  When sending messages, a user should be allowed to message a single person or all connected users in the "room".  Rooms belong to an application (I might want use this framework for real time events, for example), so selecting users to message is based on the tuple {ApplicationId, RoomId, UserId}. This is my primary key.

My question is, is it efficient to have such keys in Mnesia?  I guess I could set the table up to be ordered, which would speed up requests for records.  To get users by RoomId, I'd need to search using the key {ApplicationId, RoomId, _}.

Is this the best way to handle this?

Thanks,
Lee


More information about the erlang-questions mailing list