Sha256: c0eaf7862cbd4df6c00a69fc4fb360948e729e1ee509a5da5b11b717ace98961
Contents?: true
Size: 680 Bytes
Versions: 11
Compression:
Stored size: 680 Bytes
Contents
module Skylight module Util class EWMA attr_reader :rate def initialize(alpha) @alpha = alpha @uncounted = AtomicInteger.new @rate = nil end def update(n) @uncounted.add_and_get(n) end # Mark the passage of time and decay the current rate accordingly. # This method is obviously not thread-safe as is expected to be # invoked once every interval def tick() count = @uncounted.get_and_set(0) instantRate = count if rate rate += (alpha * (instantRate - rate)) else rate = instantRate end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems