gen_server with a dict vs mnesia table vs ets

Posted by pablo on Stack Overflow See other posts from Stack Overflow or by pablo
Published on 2010-01-28T12:14:21Z Indexed on 2010/05/02 8:07 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about erlang

Related posts about gen-server