couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [22/27] rexi commit: updated refs/heads/windsor-merge to 096f0cf
Date Fri, 01 Aug 2014 09:06:51 GMT
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 <paul.joseph.davis@gmail.com>
Authored: Thu Jan 30 22:03:09 2014 -0600
Committer: Robert Newson <rnewson@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


Mime
View raw message