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

Version Path
skylight-0.0.16 lib/skylight/util/ewma.rb
skylight-0.0.15 lib/skylight/util/ewma.rb
skylight-0.0.14 lib/skylight/util/ewma.rb
skylight-0.0.13 lib/skylight/util/ewma.rb
skylight-0.0.12 lib/skylight/util/ewma.rb
skylight-0.0.11 lib/skylight/util/ewma.rb
skylight-0.0.10 lib/skylight/util/ewma.rb
skylight-0.0.7 lib/skylight/util/ewma.rb
skylight-0.0.6 lib/skylight/util/ewma.rb
skylight-0.0.5 lib/skylight/util/ewma.rb
skylight-0.0.2 lib/skylight/util/ewma.rb