class DbSucker::Application::SklavenTreiber::Worker::IO::Throughput::Instance

Attributes

categories[R]
ioop[R]
sopts[R]

Public Class Methods

expose(what, &how) click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 105
def self.expose what, &how
  define_method(what) do |*args, &block|
    sync { instance_exec(*args, &how) }
  end
end
new(manager, ioop) click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 93
def initialize manager, ioop
  @manager = manager
  @ioop = ioop
  @monitor = Monitor.new
  @pauses = 0
  @categories = [:total]
  @tracking = []
  @tracking_offset = 0
  @sopts = { perc_modifier: 1, perc_base: 0, tracking: 5.seconds }
  reset_stats
end

Public Instance Methods

commit!() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 123
def commit!
  sync do
    ping
    return unless offset
    @manager.commit!(offset, @categories)
  end
end
measure(&block) click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 204
def measure &block
  @manager.poll!(self)
  @started_at = Time.current
  block.call(self)
ensure
  @ended_at = Time.current
  @manager.nopoll!(self)
  commit!
end
pause!() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 131
def pause!
  sync do
    return if @pause_started
    @pause_started = Time.current
  end
end
ping() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 146
def ping
  sync do
    return unless @started_at
    @stats[:bps_avg] = runtime.zero? ? 0 : (offset.to_d / runtime.to_d).to_i
    @stats[:eta2] = @stats[:bps_avg].zero? ? -1 : (bytes_remain.to_d / @stats[:bps_avg].to_d).to_i

    # eta tracking
    od = @tracking.last ? offset - @tracking_offset - @tracking.sum{|t,o| o }.to_d : 0
    @tracking << [Time.current, od] if !od.zero? || @tracking.empty?
    while @tracking.any? && @tracking.first[0] < @sopts[:tracking].ago
      @tracking_offset += @tracking.shift[1]
    end

    range = @tracking.any? ? @tracking.last[0] - @tracking.first[0] : 0
    @stats[:bps] = range.zero? ? 0 : @tracking.sum{|t,o| o }.to_d / range.to_d
    @stats[:eta] = @stats[:bps].zero? ? -1 : (bytes_remain.to_d / @stats[:bps].to_d).to_i
  end
end
reset_stats() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 169
def reset_stats
  sync do
    @tracking_offset = 0
    @tracking.clear
    @stats = { eta: -1, eta2: -1, bps: 0, bps_avg: 0 }
  end
end
sync(&block) click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 119
def sync &block
  @monitor.synchronize(&block)
end
unpause!() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 138
def unpause!
  sync do
    return unless @pause_started
    @pauses += Time.current - @pause_started
    @pause_started = false
  end
end
unregister() click to toggle source
# File lib/db_sucker/application/sklaven_treiber/worker/io/throughput.rb, line 165
def unregister
  @manager.unregister(self)
end