class Oxidized::Jobs

Constants

AVERAGE_DURATION
MAX_INTER_JOB_GAP

Attributes

interval[RW]
max[RW]
want[RW]

Public Class Methods

new(max, use_max_threads, interval, nodes) click to toggle source
Calls superclass method
# File lib/oxidized/jobs.rb, line 7
def initialize(max, use_max_threads, interval, nodes)
  @max = max
  @use_max_threads = use_max_threads
  # Set interval to 1 if interval is 0 (=disabled) so we don't break
  # the 'ceil' function
  @interval = interval.zero? ? 1 : interval
  @nodes = nodes
  @last = Time.now.utc
  @durations = Array.new @nodes.size, AVERAGE_DURATION
  duration AVERAGE_DURATION
  super()
end

Public Instance Methods

duration(last) click to toggle source
# File lib/oxidized/jobs.rb, line 25
def duration(last)
  if @durations.size > @nodes.size
    @durations.slice! @nodes.size...@durations.size
  elsif @durations.size < @nodes.size
    @durations.fill AVERAGE_DURATION, @durations.size...@nodes.size
  end
  @durations.push(last).shift
  @duration = @durations.inject(:+).to_f / @nodes.size # rolling average
  new_count
end
increment() click to toggle source
# File lib/oxidized/jobs.rb, line 47
def increment
  # Increments the job count if safe to do so, which means:
  # a) less threads running than the total amount of nodes
  # b) we want less than the max specified number of threads

  @want = [(@want + 1), @nodes.size, @max].min
end
new_count() click to toggle source
# File lib/oxidized/jobs.rb, line 36
def new_count
  @want = if @use_max_threads
            @max
          else
            ((@nodes.size * @duration) / @interval).ceil
          end
  @want = 1 if @want < 1
  @want = @nodes.size if @want > @nodes.size
  @want = @max if @want > @max
end
push(arg) click to toggle source
Calls superclass method
# File lib/oxidized/jobs.rb, line 20
def push(arg)
  @last = Time.now.utc
  super
end
work() click to toggle source
# File lib/oxidized/jobs.rb, line 55
def work
  # if   a) we want less or same amount of threads as we now running
  # and  b) we want less threads running than the total amount of nodes
  # and  c) there is more than MAX_INTER_JOB_GAP since last one was started
  # then we want one more thread (rationale is to fix hanging thread causing HOLB)
  return unless @want <= size && @want < @nodes.size

  return unless @want <= size

  increment if (Time.now.utc - @last) > MAX_INTER_JOB_GAP
end