[erlang-questions] dict vs. ETS choice

Pierre Fenoll pierrefenoll@REDACTED
Thu Jul 10 23:26:38 CEST 2014


Naturally, measure first.
Implement both methods. Switching from one to the other is trivial anyway.

For a hashtable store that is read-mostly I would suggest you use the
process dictionary instead of ETS.
I have measured a 100x speedup compared to ETS (details and implementation
here [1]).
Though you have to be careful with your writes as proc.dict. is a mutable
datastructure. You might be interested in reading this [2].

[1]: https://bitbucket.org/fenollp/tmln-google/src
[2]: http://ferd.ca/on-the-use-of-the-process-dictionary-in-erlang.html

Cheers,
-- 
Pierre Fenoll



On 10 July 2014 22:56, zxq9 <zxq9@REDACTED> wrote:

> On Thursday 10 July 2014 14:29:42 Derek Brown wrote:
> > Let's say you want to store on the order of tens of thousands key/value
> > pairs, with integer keys and proplist values (less than 10 simple
> key/value
> > pairs per proplist). Read-heavy with few writes.
> >
> > What factors would you consider when going with a dict or an ETS table,
> or
> > perhaps something else?
>
> Factors to consider? Whatever benchmarking both cases tells me. I would run
> each test case alongside a few different workloads on the same machine to
> figure out what good/bad things to expect from each approach.
>
> Someone will probably come along who actually has done this both ways and
> tell
> you there is indeed a Right Way, but usually I've found that taking the
> time
> to run some informal benchmarks provides more insight (which winds up
> useful
> elsewhere) than adherence to advice/data structure guidelines. Also, data
> structure advice often turns out to be a wordy version of "it depends..."
> and
> then a request for more information about the higher level problem you're
> actually trying to solve.
>
> What is the overall effect you're trying to achieve? It would be helpful to
> spell out the problem you're trying to solve (at the higher level like
> "how to
> best store 100k player's stats at once" instead of at the implementation
> detail of "is a dict or an ETS table better for 100k values?"). Very often
> you'll find someone has already tackled something similar and can give you
> some good advice you'd never get when asking just about the details of data
> structures. This prevents X->Y problem discussions.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140710/79eff949/attachment.htm>


More information about the erlang-questions mailing list