gen_server with a dict vs mnesia table vs ets
Asked Answered
K

1

13

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

Kronos answered 28/1, 2010 at 12:14 Comment(2)
This has been discussed on the erlang-questions mailing-list.Centi
And here's a link to the discussion, for those like me who found stackoverflow first: erlang.2086793.n4.nabble.com/…Facultative
F
19

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/...
Floorboard answered 29/1, 2010 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.