[erlang-questions] eheap_alloc crash when using mnesia

Gleb Peregud gleber.p@REDACTED
Mon Oct 20 18:36:49 CEST 2008


As far as i know, this error appears when system runs out of memory.
Unfortunately Erlang VM crashes when it's alloc() fails. imvho proper
solution would be to kill offending erlang process :)

On 10/20/08, Yongbeom Pak <ruzin82@REDACTED> wrote:
> I am trying to use mnesia heavily. It seems there are memory problem on the
> mnesia or my soruce code.
> Message i got is
> "Crash dump was written to: erl_crash.dump
> eheap_alloc: Cannot allocate 373662860 bytes of memory (of type "heap").
>
> Abnormal termination
> ".
> I have erlang 5.6.4 on windows xp sp2 and 2G of physical memory. I installed
> erlang from binary from the erlang.org
>
> Can anybody please tell me what is the problem on my source code and how to
> solve?
> I am guessing that erlang has its own limit on the heap memory size and
> garbage collector is not working fast because of some reason that i don't
> know.
>
> Thanks in advance.
>
>
> Here is my source code.
>
> -compile(export_all).
>
> -record(test, {user, data, timestamp, timestamp1}).
>
> -define(PROCNAME_UPDATER, data_updater).
>
> start_amount(N) ->
>  mnesia:start(),
>  create_table(),
>  delete(),
>  write(200000),
>  mnesia:table_info(test,size),
>  data_handler_start().
>
>
>
> data_handler_start() ->
>     case whereis(?PROCNAME_UPDATER) of
>  undefined ->
>      register(?PROCNAME_UPDATER, spawn(?MODULE, data_updater, [5000]));
>  _ ->
>      ?PROCNAME_UPDATER
>     end.
>
> stop() ->
>  ?PROCNAME_UPDATER ! stop.
>
> data_updater(Interval) ->
>     data_updater(Interval, true).
>
> data_updater(Interval, true) ->
>     timer:send_after(Interval, update),
>     receive
>  update ->
>        supdate(),
>      data_updater(Interval, true);
>  stop ->
>      ok;
>  {'EXIT', DiedPid, Reason} ->
>      io:format("~p died becausere of '~p '",[DiedPid, Reason]),
>      data_updater(Interval, true);
>  _ ->
>      data_updater(Interval, true)
>     end.
>
>
>
> create_table() ->
>  mnesia:create_table(test,
>    [{ram_copies, [node()]},
>     {index, [timestamp1]},
>     {local_content, true},
>     {attributes, record_info(fields, test)}]),
>  ok.
>
>
> write(N) ->
>  statistics(runtime),
>  write_data(N),
>  {_, Time} = statistics(runtime),
>  io:format("~nTotal writing time : ~p millisecond~n",[Time]).
>
> write_data(0) ->
>  ok;
>
> write_data(N) ->
>  {Mega, Sec, _Micro} = now(),
>  mnesia:dirty_write(test,
> #test{user={"aaaaaaaaaaaaaaaaaaaaaaaaa",random:uniform()},
>      data =
> {"aaaaaaaaaaaaaaaaaaaa","bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"},
>      timestamp = now(),
>      timestamp1 = ((Mega*1000000) + (Sec+random:uniform(10000)))
>      }),
>  write_data(N-1).
>
> select_data() ->
>  mnesia:dirty_select(test, [{'$1',[],['$1']}]).
>
> delete() ->
>  mnesia:delete_table(test),
>  create_table().
>
> supdate() ->
>  {Mega, Sec, _Micro} = now(),
>  Timesearch = ((Mega*1000000) + (Sec+random:uniform(10000))),
>  io:format("before crash point~n"),
>  mnesia:dirty_select(test,
> [{#test{user='$0',timestamp1='$1',_='_',data='$2'},
>      [{'<', '$1', Timesearch }],
>      [['$0','$2']]}]),
>  io:format("after crash point~n"),
>  io:format("---------------------------------------~n").
>


-- 
Gleb Peregud
http://gleber.pl/

Every minute is to be grasped.
Time waits for nobody.
-- Inscription on a Zen Gong



More information about the erlang-questions mailing list