Navigation Menu

Skip to content

Commit

Permalink
Calculate remaining time based on actual throughput as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 17, 2015
1 parent dd940aa commit 6441b28
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/drndump/dump_client.rb
Expand Up @@ -20,6 +20,7 @@
module Drndump
class DumpClient
DEFAULT_MESSAGES_PER_SECOND = 10000 # same to droogna-engine's one
MIN_REPORTED_THROUGHPUT = 0.01

attr_reader :n_forecasted_messages, :n_received_messages
attr_reader :error_message
Expand Down Expand Up @@ -72,6 +73,10 @@ def run(options={}, &block)
@n_messages_per_second = options[:messages_per_second] || DEFAULT_MESSAGES_PER_SECOND
@n_messages_per_second = [@n_messages_per_second, 1].max

@measure_start_time = Time.now
@previous_measure_time = @measure_start_time
@previous_n_received_messages = 0

dump_message = {
"type" => "dump",
"dataset" => @dataset,
Expand Down Expand Up @@ -137,12 +142,28 @@ def run(options={}, &block)
@error_message
end

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
end

def n_remaining_messages
[@n_forecasted_messages - @n_received_messages, 0].max
end

def remaining_seconds
n_remaining_messages.to_f / @n_messages_per_second
throughput = [recent_throughput, @n_messages_per_second].min
n_remaining_messages.to_f / throughput
end

ONE_MINUTE_IN_SECONDS = 60
Expand Down

0 comments on commit 6441b28

Please sign in to comment.