diff options
| author | Emile Joubert <emile@rabbitmq.com> | 2011-10-27 13:20:32 +0100 |
|---|---|---|
| committer | Emile Joubert <emile@rabbitmq.com> | 2011-10-27 13:20:32 +0100 |
| commit | e5c46ade80810eef1ccd0f03bf9d63f0f7799c6a (patch) | |
| tree | 45bb40236beaf952e5df673ca11c6b92645e907c | |
| parent | b75157b9a7b0f133277ba824815fb65359dfcbe0 (diff) | |
| download | rabbitmq-server-git-e5c46ade80810eef1ccd0f03bf9d63f0f7799c6a.tar.gz | |
Reduce nesting of case statements
(Courtesy of Matthias)
| -rw-r--r-- | src/rabbit_memory_monitor.erl | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/rabbit_memory_monitor.erl b/src/rabbit_memory_monitor.erl index 9cfc158327..02f3158f3b 100644 --- a/src/rabbit_memory_monitor.erl +++ b/src/rabbit_memory_monitor.erl @@ -211,22 +211,19 @@ internal_update(State = #state { queue_durations = Durations, queue_duration_sum = Sum, queue_duration_count = Count }) -> MemoryLimit = ?MEMORY_LIMIT_SCALING * vm_memory_monitor:get_memory_limit(), + MemoryRatio = case MemoryLimit > 0.0 of + true -> erlang:memory(total) / MemoryLimit; + false -> infinity + end, DesiredDurationAvg1 = - case MemoryLimit > 0.0 of - true -> - MemoryRatio = erlang:memory(total) / MemoryLimit, - case MemoryRatio < ?LIMIT_THRESHOLD orelse Count == 0 of - true -> - infinity; - false -> - Sum1 = case MemoryRatio < ?SUM_INC_THRESHOLD of - true -> Sum + ?SUM_INC_AMOUNT; - false -> Sum - end, - (Sum1 / Count) / MemoryRatio - end; - false -> - 0.0 + if MemoryRatio =:= infinity -> + 0.0; + MemoryRatio < ?LIMIT_THRESHOLD orelse Count == 0 -> + infinity; + MemoryRatio < ?SUM_INC_THRESHOLD -> + ((Sum + ?SUM_INC_AMOUNT) / Count) / MemoryRatio; + true -> + (Sum / Count) / MemoryRatio end, State1 = State #state { desired_duration = DesiredDurationAvg1 }, |
