You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/01 11:06:51 UTC

[22/27] rexi commit: updated refs/heads/windsor-merge to 096f0cf

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


Project: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/commit/e13e16f6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/tree/e13e16f6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-rexi/diff/e13e16f6

Branch: refs/heads/windsor-merge
Commit: e13e16f6a0b12985ae95b9fc220321f25a078f8a
Parents: e271ae4
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Jan 30 22:03:09 2014 -0600
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 23 18:06:30 2014 +0100

----------------------------------------------------------------------
 src/rexi_buffer.erl | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-rexi/blob/e13e16f6/src/rexi_buffer.erl
----------------------------------------------------------------------
diff --git a/src/rexi_buffer.erl b/src/rexi_buffer.erl
index b096c5b..880e4dd 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