[erlang-questions] Efficient way to store message lists in mnesia

Khitai Pang khitai.pang@REDACTED
Fri Jun 3 19:08:46 CEST 2016


I need to store a list of unread messages for every user id.  The order 
of the messages needs to be preserved.  Currently I store the messages 
in a list as the value of the user id key in a table of type set:

{user_id, [message]}

The table is a disc_copies table.

Whenever someone sends a message to a user, the message is prepended to 
the head of the message list of the user.

Now my concern is, adding a new message to the list requires reading and 
writing the whole list, which can be pretty slow if the list is very 
long, i.e. thousands of messages.

There is another way to do this, which uses a table of type bag and 
composite keys:

{user_id, timestamp1, message1}
{user_id, timestamp2, message2}
{user_id, timestamp3, message3}

But I don't think this is any better because I heard that mnesia bag 
tables performance is very bad: 

Are there other ways to store lists of messages in mnesia where 
reading/updating the message lists can be very efficient?


More information about the erlang-questions mailing list