[erlang-questions] gen_server with a dict vs mnesia table vs ets

Robert Virding rvirding@REDACTED
Thu Jan 28 16:44:13 CET 2010


It really depends very much on your app which is better:

- An ETS table will generally allow you to hold more data.
- An ETS table is external to processes so there is no cost in process GC.
- BUT there is still an ETS data GC cost every time you add or remove data.
- Since ETS data not in process there are copying costs every time you
access table. This can make some operations very expensive, but
match_object and select_object can help alot.
- A dict allows easy roll back to previous state if you keep old reference.
- ETS and dicts provide slightly different interfaces.

You could use a public ETS table, but this would not allow for more
complex atomic transactions and is not accessible over distribution.

It really does depend on what you are doing. The best is to test it
with realistic data amounts and operations. As an alternative to dicts
there are gb_trees which are also in the process memory but have
different properties compared to dicts.

Robert

2010/1/28 Pablo Platt <pablo.platt@REDACTED>:
> So I'll use a gen_server that controls the ETS table with private access.
> Thanks
>
>
>
>
> ________________________________
> From: Max Lapshin <max.lapshin@REDACTED>
> To: Pablo Platt <pablo.platt@REDACTED>
> Cc: erlang-questions@REDACTED
> Sent: Thu, January 28, 2010 3:29:48 PM
> Subject: Re: [erlang-questions] gen_server with a dict vs mnesia table vs ets
>
> On Thu, Jan 28, 2010 at 4:28 PM, Pablo Platt <pablo.platt@REDACTED> wrote:
>> The fact that ETS doesn't take part in garbage collection is a good or bad
>> feature in my case?
>
> Good, of course: you can control by yourself, when to clean objects,
> so there will be no GC-penalty on each loop
>
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
>
>
>


More information about the erlang-questions mailing list