summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2009-09-18 06:08:44 +0100
committerMatthias Radestock <matthias@lshift.net>2009-09-18 06:08:44 +0100
commitaafc8c970e2ecc90595c722c459534d02f194bf9 (patch)
treeb579ba643068a4aacb8a5d63bdbee6893261eec2 /src
parent30fdbff09d12a4806ccaf7ef536a42261e50d09b (diff)
downloadrabbitmq-server-git-aafc8c970e2ecc90595c722c459534d02f194bf9.tar.gz
handle timeouts in cpu_sup:avg1 gracefully
Also, it turns out that the load avg is an int, not a float
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_load.erl17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/rabbit_load.erl b/src/rabbit_load.erl
index 7bf85347fb..6ef638cb59 100644
--- a/src/rabbit_load.erl
+++ b/src/rabbit_load.erl
@@ -41,7 +41,7 @@
-ifdef(use_specs).
-type(erlang_node() :: atom()).
--type(load() :: {{non_neg_integer(), float()}, erlang_node()}).
+-type(load() :: {{non_neg_integer(), integer() | 'unknown'}, erlang_node()}).
-spec(local_load/0 :: () -> load()).
-spec(remote_loads/0 :: () -> [load()]).
-spec(pick/0 :: () -> erlang_node()).
@@ -52,8 +52,11 @@
local_load() ->
LoadAvg = case whereis(cpu_sup) of
- undefined -> 0.0;
- _Other -> cpu_sup:avg1()
+ undefined -> unknown;
+ _ -> case cpu_sup:avg1() of
+ L when is_integer(L) -> L;
+ {error, timeout} -> unknown
+ end
end,
{{statistics(run_queue), LoadAvg}, node()}.
@@ -65,8 +68,12 @@ remote_loads() ->
pick() ->
RemoteLoads = remote_loads(),
{{RunQ, LoadAvg}, Node} = local_load(),
- %% add bias towards current node
- AdjustedLoadAvg = LoadAvg * ?FUDGE_FACTOR,
+ %% add bias towards current node; we rely on Erlang's term order
+ %% of SomeFloat < local_unknown < unknown.
+ AdjustedLoadAvg = case LoadAvg of
+ unknown -> local_unknown;
+ _ -> LoadAvg * ?FUDGE_FACTOR
+ end,
Loads = [{{RunQ, AdjustedLoadAvg}, Node} | RemoteLoads],
{_, SelectedNode} = lists:min(Loads),
SelectedNode.