Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BE30911281 for ; Fri, 1 Aug 2014 09:06:31 +0000 (UTC) Received: (qmail 693 invoked by uid 500); 1 Aug 2014 09:06:30 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 531 invoked by uid 500); 1 Aug 2014 09:06:30 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 184 invoked by uid 99); 1 Aug 2014 09:06:30 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Aug 2014 09:06:30 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 7AB099BCAA7; Fri, 1 Aug 2014 09:06:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rnewson@apache.org To: commits@couchdb.apache.org Date: Fri, 01 Aug 2014 09:06:47 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Fri Nov 22 15:58:02 2013 -0500 Committer: Robert Newson 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.