Sha256: 11f967addd1dacddb56b3f49aee1ab2ef4290e5ec2315e4b7e8d7b628a5d24ae
Contents?: true
Size: 1.11 KB
Versions: 11
Compression:
Stored size: 1.11 KB
Contents
require 'thread' module Skylight module Metrics class Meter def initialize(ewma = EWMA.one_minute_ewma, clock = Util::Clock.default) @ewma = ewma @lock = Mutex.new @clock = clock @start_time = @clock.tick @last_tick = @start_time end def mark(n = 1) @lock.synchronize do tick_if_necessary @ewma.update(n) end end def rate @lock.synchronize do tick_if_necessary @ewma.rate(1) end end def call rate end private def tick_if_necessary old_tick = @last_tick new_tick = @clock.tick # How far behind are we age = new_tick - old_tick if age >= @ewma.interval new_tick = new_tick - age % @ewma.interval # Update the last seen tick @last_tick = new_tick # Number of missing ticks required_ticks = age / @ewma.interval while required_ticks > 0 @ewma.tick required_ticks -= 1 end end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems