[erlang-questions] Mnesia table-fragmentation memory problem.

Gustav Simonsson <>
Tue Nov 29 17:53:31 CET 2011


Erlang R14B04 (erts-5.8.5) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
Mac OS X 10.6.8 (Darwin 10.8.0 Darwin Kernel Version 10.8.0: ; root:xnu-1504.15.3~1/RELEASE_I386 i386)

Trying to get Mnesia table fragmentation to work;
I have a scenario where Mnesia is started on one node, with one table. 
The table is defined with table fragmentation and disc_only_copies:

mnesia:create_schema([node()]),
mnesia:start(),
MnesiaProperties = [{type, set}, {frag_properties, 
                     [{node_pool, [node()]}, {n_fragments, 20}, 
                      {n_disc_only_copies, 1}]}],
{atomic, ok} = mnesia:create_table(test, MnesiaProperties),

then later in a gen_server, on receiving a message I do:

F2 = 
    fun() ->
            Data = data(),
            F =
                fun() ->
                        mnesia:write(test, #test{foo = Id, bar = Data}, write)
                end,
            ok = mnesia:activity(async_dirty, F, [], mnesia_frag)
    end,

spawn(F2),

Data is around 46MB of dummy data, and Id is an integer.
This is done every 3s.

My understanding is that this would only generate data on disk, however the memory
usage slowly increases until the BEAM crashes.

Sorting the processes by heap_size and looking at their current_function, I see
that for each write of data, a process remains with current_function
{dets,open_file_loop2,2} and a heap_size corresponding to the size of the data at each Mnesia write.

Eventually many such processes fill up the available memory and the VM crashes.

The code was also tested (with the same problem arising) on:
Erlang R15B (erts-5.9) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
Linux 2.6.38-11-generic #50-Ubuntu SMP i686 i686 i386 GNU/Linux

Any ideas?

Regards,
Gustav Simonsson

Sent from my PC




More information about the erlang-questions mailing list