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:47 UTC

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

Don't block the governor to send a message

This allows the governor to continue prioritizing incoming requests
instead of hanging for several seconds to try to connect to the remote
node.

BugzID: 23717
BugzID: 23718


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

Branch: refs/heads/windsor-merge
Commit: 8f9d160c688af025179b0f61be972a00b33f5fad
Parents: 664f0b8
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Fri Nov 22 15:58:02 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Wed Jul 23 18:03:23 2014 +0100

----------------------------------------------------------------------
 src/rexi_governor.erl | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-rexi/blob/8f9d160c/src/rexi_governor.erl
----------------------------------------------------------------------
diff --git a/src/rexi_governor.erl b/src/rexi_governor.erl
index fdf8c93..12ec013 100644
--- a/src/rexi_governor.erl
+++ b/src/rexi_governor.erl
@@ -25,6 +25,7 @@
 
 -record(state, {
     buffer = queue:new(),
+    sender = nil,
     count = 0
 }).
 
@@ -55,19 +56,30 @@ handle_cast({deliver, Dest, Msg}, #state{buffer = Q, count = C} = State) ->
             {noreply, State#state{buffer = Q2, count = C+1}, 0}
     end.
 
-handle_info(timeout, State) ->
+handle_info(timeout, #state{sender = nil} = State) ->
     #state{buffer = Q, count = C} = State,
-    case queue:out_r(Q) of
+    Sender = case queue:out_r(Q) of
         {{value, {Dest, Msg}}, Q2} ->
-            erlang:send(Dest, Msg);
+            case erlang:send(Dest, Msg, [noconnect, nosuspend]) of
+                ok ->
+                    nil;
+                _Else ->
+                    spawn_monitor(erlang, send, [Dest, Msg])
+            end;
         {empty, Q2} ->
-            ok
+            nil
     end,
-    if C > 1 ->
+    if Sender =:= nil, C > 1 ->
         {noreply, State#state{buffer = Q2, count = C-1}, 0};
     true ->
-        {noreply, State#state{buffer = Q2, count = 0}}
-    end.
+        {noreply, State#state{buffer = Q2, sender = Sender, count = C-1}}
+    end;
+handle_info(timeout, State) ->
+    % Waiting on a sender to return
+    {noreply, State};
+
+handle_info({'DOWN', Ref, _, Pid, _}, #state{sender = {Pid, Ref}} = State) ->
+    {noreply, State#state{sender = nil}, 0}.
 
 terminate(_Reason, _State) ->
     ok.