views:

240

answers:

1

Hi,

I'm building an erlang server. Users sends http requests to the server to update their status. The http request process on the server saves the user status message in memory. Every minute the server sends all messages to a remote server and clear the memory. If a user update his status several times in a minute, the last message overrides the previous one. It is important that between reading all the messages and clearing them no other process will be able to write a status message.

What is the best way to implement it?

  1. gen_server with a dict. The key will be the userid. dict:store/3 will update or create the status. The gen_server solves the 'transaction' issue.

  2. mnesia table with ram_copies. Handle transactions and I don't need to implement a gen_server. Is there too much overhead with this solution?

  3. ETS table which is more light weight and have a gen_server. Is it possible to do the transaction in ETS? To lock the table between reading all the messages and clearing them?

Thanks

+1  A: 

Since you do the syncing manually, mnesia is to much. You clearly don't need the networking stuff, thats the main difference between ets and mnesia.

Ets, as far as I undertand, is just a otp compliant process around a dict/bag/..., and since you have multiple processes accessing your data, you should use ets.

I came up with the following logic for myself:

Multiple processes on multiple VMs -> mnesia
Multiple processes on one VM -> ets/dets
One process -> bag/dict/...
ZeissS