summaryrefslogtreecommitdiff
path: root/src/background_gc.erl
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2012-11-12 14:39:39 +0000
committerSimon MacMullen <simon@rabbitmq.com>2012-11-12 14:39:39 +0000
commit9d552a8fd2b6ab12830eaf83d7a84680eb392953 (patch)
treee94dc88a453e7e527892cae7ad265b7299fee489 /src/background_gc.erl
parent9f3e80195c4cf485908e2a50823539657180dacd (diff)
downloadrabbitmq-server-9d552a8fd2b6ab12830eaf83d7a84680eb392953.tar.gz
Only GC idle (waiting) processes. Filter tiny processes from the list (to make generating the list more efficient when there are huge numbers of processes). Probabilistic process selection.
Diffstat (limited to 'src/background_gc.erl')
-rw-r--r--src/background_gc.erl18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/background_gc.erl b/src/background_gc.erl
index 36a3c387..4722997a 100644
--- a/src/background_gc.erl
+++ b/src/background_gc.erl
@@ -28,6 +28,7 @@
-define(MAX_RATIO, 0.01).
-define(IDEAL_INTERVAL, 5000).
+-define(MIN_BYTES, 50000).
-record(state, {last_interval}).
@@ -69,13 +70,14 @@ run_gc(State = #state{last_interval = LastInterval}) ->
State#state{last_interval = Interval}.
do_gc() ->
- Sorted = lists:reverse(lists:sort(
- [{memory(Pid), Pid} || Pid <- processes()])),
- %% TODO select probabilisticly.
- garbage_collect(element(2, hd(Sorted))),
+ 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),
ok.
-memory(Pid) -> case process_info(Pid, memory) of
- {memory, M} -> M;
- _ -> 0
- end.
+rs(L) -> lists:reverse(lists:sort(L)).
+
+stats(P) -> [erlang:process_info(P, [status, memory])].