Method: Async::Scheduler#load

Defined in:
lib/async/scheduler.rb

#loadObject

Compute the scheduler load according to the busy and idle times that are updated by the run loop.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/async/scheduler.rb', line 106

def load
  total_time = @busy_time + @idle_time
  
  # If the total time is zero, then the load is zero:
  return 0.0 if total_time.zero?
  
  # We normalize to a 1 second window:
  if total_time > 1.0
    ratio = 1.0 / total_time
    @busy_time *= ratio
    @idle_time *= ratio
    
    # We don't need to divide here as we've already normalised it to a 1s window:
    return @busy_time
  else
    return @busy_time / total_time
  end
end