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 | 8029ba58784e1708312fe3bd2c47f5e69db89448 (patch) | |
| tree | 6c1f757e495063494e19c02bf7e3e466b53bb2f1 | |
| parent | c8df9d8ad0c7a6b500f32c71601a7daee98cc6a0 (diff) | |
| download | rabbitmq-server-git-8029ba58784e1708312fe3bd2c47f5e69db89448.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 4722997a0b..0753dd6770 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])]. |
