diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2014-01-30 22:03:09 -0600 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2014-07-23 18:06:30 +0100 |
commit | e13e16f6a0b12985ae95b9fc220321f25a078f8a (patch) | |
tree | 133c0a8b25677585984ad62ba39e6589e684a2a2 | |
parent | e271ae4666d908a8cb4b33002b46f9da0f3611e6 (diff) | |
download | couchdb-e13e16f6a0b12985ae95b9fc220321f25a078f8a.tar.gz |
Hibernate rexi_buffer when becoming idle
The rexi_buffer gen_server can hold onto quite a bit of RAM during idle
operation. This just checks when we're going back to the idle state and
hibernates until the next message arrives. This ensures that we run
garbage collection before sitting idle.
BugzId: 27672
-rw-r--r-- | src/rexi_buffer.erl | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/rexi_buffer.erl b/src/rexi_buffer.erl index b096c5bb8..880e4dd6c 100644 --- a/src/rexi_buffer.erl +++ b/src/rexi_buffer.erl @@ -72,7 +72,16 @@ handle_info(timeout, #state{sender = nil} = State) -> if Sender =:= nil, C > 1 -> {noreply, State#state{buffer = Q2, count = C-1}, 0}; true -> - {noreply, State#state{buffer = Q2, sender = Sender, count = C-1}} + % When Sender is nil and C-1 == 0 we're reverting to an + % idle state with no outstanding or queued messages. We'll + % use this oppurtunity to hibernate this process and + % run a garbage collection. + Timeout = case {Sender, C-1} of + {nil, 0} -> hibernate; + _ -> infinity + end, + NewState = State#state{buffer = Q2, sender = Sender, count = C-1}, + {noreply, NewState, Timeout} end; handle_info(timeout, State) -> % Waiting on a sender to return |