class Ring::SQA::Analyzer

Constants

INFLIGHT_WAIT
INTERVAL

Public Class Methods

new(database, nodes) click to toggle source
# File lib/ring/sqa/analyzer.rb, line 37
def initialize database, nodes
  @db         = database
  @nodes      = nodes
  @alarm      = Alarm.new @nodes
  @buffer     = AnalyzeBuffer.new @nodes.all.size
  @db_id_seen = 0
  @graphite   = graphite if CFG.graphite?
end

Public Instance Methods

run() click to toggle source
# File lib/ring/sqa/analyzer.rb, line 9
def run
  sleep INTERVAL
  loop do
    start = Time.now
    @db.purge
    first_id = @db_id_seen+1
    @db_id_seen, records = @db.nodes_down(first_id)
    sleep INFLIGHT_WAIT
    records = records.all
    @graphite.add @db.id_range(first_id, @db_id_seen).all if @graphite
    @buffer.push records.map { |record| record.peer }
    @buffer.exceed_median? ? @alarm.set(@buffer) : @alarm.clear(@buffer)
    delay = INTERVAL-(Time.now-start)
    # in case delay happens to be too big
    if delay > INTERVAL
      delay = INTERVAL
      Log.warn "delay became larger than #{INTERVAL}, capping it. (did ntp just sync?)"
    end
    if delay > 0
      sleep delay
    else
      Log.error "Analyzer loop took longer than #{INTERVAL}, wanted to sleep for #{delay}s"
    end
  end
end

Private Instance Methods

graphite() click to toggle source
# File lib/ring/sqa/analyzer.rb, line 46
def graphite
  require_relative 'graphite'
  Graphite.new @nodes
end