diff options
| author | Simon MacMullen <simon@rabbitmq.com> | 2014-03-11 14:07:40 +0000 |
|---|---|---|
| committer | Simon MacMullen <simon@rabbitmq.com> | 2014-03-11 14:07:40 +0000 |
| commit | 07be80d89e1d55fbc7e08727fbfb0069b574f9de (patch) | |
| tree | 4a48164b04f8ce69fba9b25a8e374f07797e8446 | |
| parent | 442cc36f9f76d73f5af8e5c33a223fa8648521b0 (diff) | |
| download | rabbitmq-server-git-07be80d89e1d55fbc7e08727fbfb0069b574f9de.tar.gz | |
Avoid connecting to nodes that are down.
| -rw-r--r-- | src/pmon.erl | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/pmon.erl b/src/pmon.erl index 8630816746..e76ebd2f7f 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. |
