diff options
| author | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2015-08-11 18:15:59 +0200 |
|---|---|---|
| committer | Jean-Sébastien Pédron <jean-sebastien@rabbitmq.com> | 2015-08-11 18:15:59 +0200 |
| commit | 7f3ab57c3846b98f7a8de055a384465013d02f82 (patch) | |
| tree | c55b62db6e8038d66e4c6711d96990297cf1efd7 | |
| parent | ddd9179c70070c05403ec00abc65298607cb613a (diff) | |
| download | rabbitmq-server-git-7f3ab57c3846b98f7a8de055a384465013d02f82.tar.gz | |
Avoid division by 0
erlang:monotonic_time() does not strictly increase: two subsequent calls
can return the same value.
References #233.
| -rw-r--r-- | src/rabbit_queue_consumers.erl | 2 | ||||
| -rw-r--r-- | src/rabbit_variable_queue.erl | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/src/rabbit_queue_consumers.erl b/src/rabbit_queue_consumers.erl index 34e447ccd3..3ba9f89205 100644 --- a/src/rabbit_queue_consumers.erl +++ b/src/rabbit_queue_consumers.erl @@ -463,6 +463,8 @@ update_use({inactive, Since, Active, Avg}, active) -> Now = time_compat:monotonic_time(micro_seconds), {active, Now, use_avg(Active, Now - Since, Avg)}. +use_avg(0, 0, Avg) -> + Avg; use_avg(Active, Inactive, Avg) -> Time = Inactive + Active, rabbit_misc:moving_average(Time, ?USE_AVG_HALF_LIFE, Active / Time, Avg). diff --git a/src/rabbit_variable_queue.erl b/src/rabbit_variable_queue.erl index 99ea33b973..f66ba21605 100644 --- a/src/rabbit_variable_queue.erl +++ b/src/rabbit_variable_queue.erl @@ -809,7 +809,11 @@ update_rates(State = #vqstate{ in_counter = InCount, update_rate(Now, TS, Count, Rate) -> Time = time_compat:convert_time_unit(Now - TS, native, micro_seconds) / ?MICROS_PER_SECOND, - rabbit_misc:moving_average(Time, ?RATE_AVG_HALF_LIFE, Count / Time, Rate). + if + Time == 0 -> Rate; + true -> rabbit_misc:moving_average(Time, ?RATE_AVG_HALF_LIFE, + Count / Time, Rate) + end. ram_duration(State) -> State1 = #vqstate { rates = #rates { in = AvgIngressRate, |
