[erlang-questions] Mnesia memory, size and effects of table copy types

Paulo Sérgio Almeida <>
Thu Jul 2 15:31:09 CEST 2009


Hi,

Matthew Sackman wrote:

>> [ mnesia:dirty_write(mytable, {mytable, N, <<0:8192>>}) || N <- lists:seq(1, 1000000) ].
> [ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,ok,
>  ok,ok,ok,ok,ok,ok,ok,ok,ok,ok|...]
>> mnesia:table_info(mytable, size).                                                       
> 1000000
>> mnesia:table_info(mytable, memory).                                                     
> 17144943

You are inserting large binaries which are not accounted for here. Only 
the references to them.

> The minimum number of words is some 7 times bigger than the amount of
> memory reported when using ets. However, I can well believe this
> assuming we don't really have 1e6 copies of that binary.

I tested and we have really 1e6 copies of that binary. i.e. doing

   [ets:insert(aaa, {N, <<0:8192>>}) || N <- lists:seq(1,1000000)]

consumes much more memory than doing:

   B = <<0:8192>>,
   [ets:insert(aaa, {N, B}) || N <- lists:seq(1,1000000)].

This means that binary constants have a different behaviour than other 
constants. (Now there is a global pool for constants to avoid recreating 
them e.g. once each function invocation.) Is this accidental or some 
design decision, considering that the above is not common and that one 
wants to frequently append things to binaries?

Regards,
Paulo


More information about the erlang-questions mailing list