diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2014-07-29 11:02:41 +0100 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2014-07-29 11:02:41 +0100 |
| commit | a3022d616cf878c81b8dc0694f0fc66971186dad (patch) | |
| tree | 96f24427e529de9f7fddd4b525bedb164bef68b2 /src | |
| parent | 3c7edeb459cb853d6461ca62af0ec43bd8d2e22d (diff) | |
| parent | 0e32feb1e29996f6df3ac662483ec45781a429e3 (diff) | |
| download | rabbitmq-server-git-a3022d616cf878c81b8dc0694f0fc66971186dad.tar.gz | |
Merge bug26159
Diffstat (limited to 'src')
| -rw-r--r-- | src/pmon.erl | 22 | ||||
| -rw-r--r-- | src/rabbit_misc.erl | 7 |
2 files changed, 26 insertions, 3 deletions
diff --git a/src/pmon.erl b/src/pmon.erl index ae1be40c0e..de3e9fea40 100644 --- a/src/pmon.erl +++ b/src/pmon.erl @@ -54,8 +54,13 @@ new(Module) -> #state{dict = dict:new(), monitor(Item, S = #state{dict = M, module = Module}) -> case dict:is_key(Item, M) of true -> S; - false -> S#state{dict = dict:store( - Item, Module:monitor(process, Item), M)} + false -> case node_alive_shortcut(Item) of + true -> Ref = Module:monitor(process, Item), + S#state{dict = dict:store(Item, Ref, M)}; + false -> self() ! {'DOWN', fake_ref, process, Item, + nodedown}, + S + end end. monitor_all([], S) -> S; %% optimisation @@ -76,3 +81,16 @@ erase(Item, S = #state{dict = M}) -> S#state{dict = dict:erase(Item, M)}. monitored(#state{dict = M}) -> dict:fetch_keys(M). is_empty(#state{dict = M}) -> dict:size(M) == 0. + +%%---------------------------------------------------------------------------- + +%% We check here to see if the node is alive in order to avoid trying +%% to connect to it if it isn't - this can cause substantial +%% slowdowns. We can't perform this shortcut if passed {Name, Node} +%% since we would need to convert that into a pid for the fake 'DOWN' +%% message, so we always return true here - but that's OK, it's just +%% an optimisation. +node_alive_shortcut(P) when is_pid(P) -> + lists:member(node(P), [node() | nodes()]); +node_alive_shortcut({_Name, _Node}) -> + true. diff --git a/src/rabbit_misc.erl b/src/rabbit_misc.erl index 58e93a3f9e..006bbadfb8 100644 --- a/src/rabbit_misc.erl +++ b/src/rabbit_misc.erl @@ -899,8 +899,13 @@ ntoab(IP) -> _ -> "[" ++ Str ++ "]" end. +%% We try to avoid reconnecting to down nodes here; this is used in a +%% loop in rabbit_amqqueue:on_node_down/1 and any delays we incur +%% would be bad news. is_process_alive(Pid) -> - rpc:call(node(Pid), erlang, is_process_alive, [Pid]) =:= true. + Node = node(Pid), + lists:member(Node, [node() | nodes()]) andalso + rpc:call(Node, erlang, is_process_alive, [Pid]) =:= true. pget(K, P) -> proplists:get_value(K, P). pget(K, P, D) -> proplists:get_value(K, P, D). |
