Navigation Menu

Skip to content

Commit

Permalink
Avoid zero divide error when the now time is same to previous time
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 17, 2015
1 parent b292d4d commit c08c31a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/drndump/dump_client.rb
Expand Up @@ -145,16 +145,23 @@ def run(options={}, &block)
def recent_throughput
now = Time.now
n_messages = @n_received_messages - @previous_n_received_messages

if now - @previous_measure_time < 1
now = @previous_measure_time
n_messages = @previous_n_received_messages
else
@previous_measure_time = now
@previous_n_received_messages = n_messages.to_f
end
elapsed_seconds = now - @measure_start_time

[n_messages / elapsed_seconds, MIN_REPORTED_THROUGHPUT].max
if now == @measure_start_time
actual_throughput = 0
else
elapsed_seconds = now - @measure_start_time
actual_throughput = n_messages / elapsed_seconds
end

[actual_throughput, MIN_REPORTED_THROUGHPUT].max
end

def n_remaining_messages
Expand Down

0 comments on commit c08c31a

Please sign in to comment.