[erlang-questions] Memory issue: big swap usage

龙第九子 <>
Mon Jul 16 10:02:21 CEST 2012


Hi all,

Recently I wrote a service-monitoring program in Erlang. It uses httpc
(the HTTP client shipped with Erlang/OTP) to fetch web server
statistics data, does some calculations, and then sends results to
another service. It works fine, however, the memory usage is very
strange. While VmRSS stays at a reasonable level, but VmSize and
VmData keep increasing (about 40m per day). Please look at the
following data:

System memory usage:

    $ free -m
                 total       used       free     shared    buffers     cached
    Mem:          2012       1486        525          0        216        713
    -/+ buffers/cache:        557       1455
    Swap:         2047          5       2041


`top` shows that the beam.smp process consumes 51m physical memory :)
and 857m swap memory :(

      PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  SWAP COMMAND
    27100 root      20   0  909m  51m 2288 S    2  2.6 149:54.65 857m beam.smp


Current VM status of the process:

    $ cat /proc/27100/status|grep Vm
    VmPeak:      932260 kB
    VmSize:      931616 kB
    VmLck:           0 kB
    VmHWM:       54624 kB
    VmRSS:       52968 kB
    VmData:      907556 kB
    VmStk:          88 kB
    VmExe:        1860 kB
    VmLib:        2412 kB
    VmPTE:         208 kB


And Erlang reported memory usage (seems good):

    15> erlang:memory().
    [{total,46487136},
     {processes,1283144},
     {processes_used,1251480},
     {system,45203992},
     {atom,509577},
     {atom_used,497728},
     {binary,169912},
     {code,4395539},
     {ets,323224}]


I use Erlang R14B03 (erts-5.8.4) compiled with GCC 4.4.5 on Debian 6
Linux 2.6.32-5-amd64. I'm not sure if there is a memory-leaking bug.
The problem is too hard for me and I have no choice but to restart the
process. Could someone be kind enough to help me out? Please.



More information about the erlang-questions mailing list