diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-11-12 15:37:20 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-11-12 15:37:20 +0000 |
commit | 91357ca49377138bcc66c8c4a631763118f17493 (patch) | |
tree | 6c1f757e495063494e19c02bf7e3e466b53bb2f1 | |
parent | 9d552a8fd2b6ab12830eaf83d7a84680eb392953 (diff) | |
download | rabbitmq-server-91357ca49377138bcc66c8c4a631763118f17493.tar.gz |
Profiling suggests that garbage_collect/1 is in fact far cheaper than processes/0, so just GC all waiting processes. And therefore reduce the frequency we call this with.
-rw-r--r-- | src/background_gc.erl | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/background_gc.erl b/src/background_gc.erl index 4722997a..0753dd67 100644 --- a/src/background_gc.erl +++ b/src/background_gc.erl @@ -27,7 +27,7 @@ -define(DESIRED_HIBERNATE, 10000). -define(MAX_RATIO, 0.01). --define(IDEAL_INTERVAL, 5000). +-define(IDEAL_INTERVAL, 60000). -define(MIN_BYTES, 50000). -record(state, {last_interval}). @@ -35,7 +35,8 @@ %%---------------------------------------------------------------------------- start_link() -> - gen_server2:start_link(?MODULE, [], [{timeout, infinity}]). + gen_server2:start_link({local, ?MODULE}, ?MODULE, [], + [{timeout, infinity}]). %%---------------------------------------------------------------------------- @@ -70,14 +71,6 @@ run_gc(State = #state{last_interval = LastInterval}) -> State#state{last_interval = Interval}. do_gc() -> - MPs = rs([{M, P} || P <- processes(), - [{status, waiting}, {memory, M}] <- stats(P), - M > ?MIN_BYTES]), - Idx = trunc(math:pow(length(MPs) + 1, random:uniform())), - {_, Pid} = lists:nth(Idx, MPs), - garbage_collect(Pid), + [garbage_collect(P) || P <- processes(), + {status, waiting} == process_info(P, status)], ok. - -rs(L) -> lists:reverse(lists:sort(L)). - -stats(P) -> [erlang:process_info(P, [status, memory])]. |