Why would a <3K heap take 300+ milliseconds to GC?

Scott Lystig Fritchie <>
Mon May 17 08:34:41 CEST 2010

Hi, sorry this is more of a something-looks-too-weird-to-be-good thing
and not an honest bug.  We've witnessed a couple of processes on an
R13B04 node that started taking over 50 milliseconds for a single GC of
a less-than-3K heap ... then stretching to over 300 milliseconds for
(what should be) the same amount of garbage.

Things get weird the longer these two procs run.  They gradually start
triggering 'long_gc' events, where the minimum threshold was 50ms.  They
reach a plateu of roughly 1150-1350 reports/day/process for a few days,
then the # of reports/day/process goes exponential: 32K reports in about
half of one day, i.e. a GC performed for nearly every timer message

The worst single GC time is 349ms.

The rest of the VM was not very busy: less than 20% CPU used on average
for an 8 core box.  On May 14th, the day that the long_gc reporting
happened nearly once/sec, each for 150-270 milliseconds each, average CPU
consumption increased only very slightly.

Does this ring a bell?  It's really, really strange behavior which (we
think) culminated into some behavior unbecoming of a well-behaved
virtual machine.  If this was a legit signal that something was going
wrong, it's worth pursuing IMHO.  I can provide the code for the
gen_server if it'd be helpful.


Distribution of long_gc times

Frequency     Range
---------     -----
     2543      50-100 milliseconds
    21003     100-199 milliseconds
    22704     200-299 milliseconds
      417     300-349 milliseconds

What the proc does

The process receives a message once/second from an external timer that
tells it to net_adm:ping/1 a remote node and then rpc:call/4 to the
application controller to get the list of apps running on the remote
node.  The proc's #state record is roughly 6 fields, contains no
binaries, and only 1 field is ever updated (with a boolean) on each
iteration.  The application being monitored is never running, so the
same code path is taken (and thus (hopefully) the same amount of
garbage) each time.

Count of # of long_gc events per day, plus random sample of monitor message

NOTE: There were two processes that were reporting these odd long_gc
events, <0.283.0> and <0.285.0>.  These are the counts for only one of
those two procs.

foreach i ( ?? )         ## directories per day, numbered 03-14
  echo -n $i " "
  cat $i/*/*/* | egrep long_gc | egrep '0.283.0' | wc -l
 cat $i/*/*/* | egrep long_gc | tail -1
 echo ""
03  0

04  0

05  7

06  341

07  1195

08  1152

09  1238

10  1324

11  1332

12  1340

13  6198

14  32540

Stack backtrace of <0.283.0>

State: Scheduled
Spawned as: proc_lib:init_p/5
Spawned by: <0.92.0>
Started: Fri Mar 26 13:26:55 2010
Message queue length: 1
Message queue: [check_status]
Number of heap fragments: 0
Heap fragment data: 0
Link list: []
Reductions: 472532540
Stack+heap: 987
OldHeap: 2584
Heap unused: 373
OldHeap unused: 2584
Stack dump:
Program counter: 0x00002aaaaab9f2c8 (gen_server:loop/6 + 288)
CP: 0x0000000000000000 (invalid)
arity = 0

0x00002aaac7d6c120 Return addr 0x00002aaaace58d70
(proc_lib:init_p_do_apply/3 + 56)
y(0)     []
y(1)     infinity
y(2)     brick_clientmon
y(4)     <0.283.0>
y(5)     <0.92.0>

0x00002aaac7d6c158 Return addr 0x0000000000867be8 (<terminate process
y(0)     Catch 0x00002aaaace58d90 (proc_lib:init_p_do_apply/3 + 88)

More information about the erlang-bugs mailing list