Search code examples
erlangmnesia

Erlang - Is it possible to limit the ram consumption when using disc copies in Mnesia?


I have a 4GB ram in my system and it used 2GB of ram before the insertion completed wen using disc_copies. I was wondering what would happen if 100 percent of the ram was consumed? Is there any option to limit the ram consumed during disc_copies, like limiting the ram usage to 2GB?


Solution

  • If you are looking how to limit erlang VM memory usage you should use control groups for it. But if you like to monitor memory usage you should use memory monitor memsup from os_mon application.

    $ erl -boot start_sasl
    Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
    
    ...    
    =PROGRESS REPORT==== 22-Oct-2015::22:39:46 ===
             application: sasl
              started_at: nonode@nohost
    Eshell V7.0  (abort with ^G)
    1> application:start(os_mon).
    ...    
    =PROGRESS REPORT==== 22-Oct-2015::22:40:03 ===
             application: os_mon
              started_at: nonode@nohost
    ok
    2> 
    ...
    2> memsup:get_memory_data().
    {8162500608,6514708480,{<0.7.0>,426616}}
    3> memsup:get_system_memory_data().
    [{system_total_memory,8162500608},
     {free_swap,5996748800},
     {total_swap,5997850624},
     {cached_memory,3290759168},
     {buffered_memory,444370944},
     {free_memory,1647222784},
     {total_memory,8162500608}]
    4>
    

    Read os_mon documentation about usage and alarms.