Q0: there is not a single best key type, and you are on the right track to find the one that is best suited for your scenario: do a lot of experiments and measurements :) Personally I would advise against using atoms when you use a lot of dynamically generated keys, they are not designed for that.<br><br>Q1: the numbers you quote are the sizes for in-memory representation. Atoms use 1 word in memory because there is a lookup table for them. When you write the data to disc, all characters have to be stored, and the difference between these types will be small.<br><br><br>L.<br><br>On Wednesday, January 9, 2013 8:27:53 AM UTC+1, nanun wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I used _list_ as key of table.<br>Now I need more faster and lighter so I tested some.<br><br>Before I tested, I think that _atom_ is the fastest and smaller mnesia files.<br>And I thought that _binary_ is the best candidate because _atom_ has issue of garbage collection.<br>
<br>But test results make me confused.<br><br>Q0. What is the best type as key?<br><br>== test results ==<br><br>There are three candidates; list, binary and atom.<br><br>100k keys;<br> list keys are "k1000001" ~ "k1100000",<br>
binary keys are <<"k1000001">> ~ <<"k1100000">>,<br> atom keys are k1000001 ~ k1100000.<br><br>I tested both mnesia types; disc_copy and disc_only_copy<br><br>Q1. Mnesia file sizes are strange, what's wrong?<br>
- disc_copy<br> size table_type<br> 3100089 atom.DCD<br> 3300089 binary.DCD<br> 3100089 list.DCD<br>- disc_only_copy<br> size table_type<br> 5391992 list_o.DAT<br> 6489808 binary_o.DAT<br> 6130276 atom_o.DAT<br>
<br> * Every key has same value.<br> * checked the sizes after q().<br><br><br> accoding to <a href="http://erlang.org/doc/efficiency_guide/advanced.html" target="_blank">http://erlang.org/doc/<wbr>efficiency_guide/advanced.html</a><br> list : 1 word + 2 words * 8(length of a list) = 17 words<br>
binary : 3..6 + 8(length of a list) = 11 ~ 14 words<br> atom : 1 word<br> so I thought the size order will list > binary >> atom.<br><br>Q2. Why atom is not fastest? atom is sometimes the slowest.<br> atom read : 61.095<br>
binary read : 65.729<br> list read : 84.162<br><br> atom write : 858.18<br> binary write : 913.092<br> list write : 861.357<br><br> atom_o read : 1657.427<br> binary_o read : 1453.002<br> list_o read : 1482.138<br>
<br> atom_o write : 1765.436<br> binary_o write : 2261.9<br> list_o write : 2289.084<br><br> * read and write every tables(100k)<br> * tried to avoid difference of period to get a key.<br> * milli seconds<br>
<br>* I think that the best type is _integer_, but I want use one of them.<br><br>thanks.<br>/nanun<br>
</blockquote>