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 | c8df9d8ad0c7a6b500f32c71601a7daee98cc6a0 (patch) | |
| tree | e94dc88a453e7e527892cae7ad265b7299fee489 /src | |
| parent | 647c9680951ff1c38306672b4d92ab3fdec3e9a9 (diff) | |
| download | rabbitmq-server-git-c8df9d8ad0c7a6b500f32c71601a7daee98cc6a0.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')
| -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 36a3c387d5..4722997a0b 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])]. |
