diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-11-12 14:39:39 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-11-12 14:39:39 +0000 |
commit | 9d552a8fd2b6ab12830eaf83d7a84680eb392953 (patch) | |
tree | e94dc88a453e7e527892cae7ad265b7299fee489 | |
parent | 9f3e80195c4cf485908e2a50823539657180dacd (diff) | |
download | rabbitmq-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.
-rw-r--r-- | src/background_gc.erl | 18 |
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])]. |