[erlang-questions] What is the best type as key of mnesia table?
Kyungho Yun
inanun@REDACTED
Wed Jan 9 08:27:53 CET 2013
I used _list_ as key of table.
Now I need more faster and lighter so I tested some.
Before I tested, I think that _atom_ is the fastest and smaller mnesia
files.
And I thought that _binary_ is the best candidate because _atom_ has issue
of garbage collection.
But test results make me confused.
Q0. What is the best type as key?
== test results ==
There are three candidates; list, binary and atom.
100k keys;
list keys are "k1000001" ~ "k1100000",
binary keys are <<"k1000001">> ~ <<"k1100000">>,
atom keys are k1000001 ~ k1100000.
I tested both mnesia types; disc_copy and disc_only_copy
Q1. Mnesia file sizes are strange, what's wrong?
- disc_copy
size table_type
3100089 atom.DCD
3300089 binary.DCD
3100089 list.DCD
- disc_only_copy
size table_type
5391992 list_o.DAT
6489808 binary_o.DAT
6130276 atom_o.DAT
* Every key has same value.
* checked the sizes after q().
accoding to http://erlang.org/doc/efficiency_guide/advanced.html
list : 1 word + 2 words * 8(length of a list) = 17 words
binary : 3..6 + 8(length of a list) = 11 ~ 14 words
atom : 1 word
so I thought the size order will list > binary >> atom.
Q2. Why atom is not fastest? atom is sometimes the slowest.
atom read : 61.095
binary read : 65.729
list read : 84.162
atom write : 858.18
binary write : 913.092
list write : 861.357
atom_o read : 1657.427
binary_o read : 1453.002
list_o read : 1482.138
atom_o write : 1765.436
binary_o write : 2261.9
list_o write : 2289.084
* read and write every tables(100k)
* tried to avoid difference of period to get a key.
* milli seconds
* I think that the best type is _integer_, but I want use one of them.
thanks.
/nanun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130109/cd921da8/attachment.htm>
More information about the erlang-questions
mailing list