Commit 091b77f7 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

improved average gauge value calculation performance, version bump to 1.2.5

parent c55ba778
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -28,10 +28,11 @@ module FnordMetric::GaugeCalculations
    _v = if respond_to?(:_value_at)
      _value_at(key, _t)
    else
      _c = sync_redis.hget(key(:"mean-counts"), _t)
      sync_redis.hget(key, _t)
    end

    calculate_value(_v, _t, opts, block)
    calculate_value(_v, _t, opts, block, _c)
  end

  def values_at(times, opts={}, &block)
@@ -40,20 +41,22 @@ module FnordMetric::GaugeCalculations
      if respond_to?(:_values_at)
        _values_at(times, opts={}, &block)
      else
        ret_counts = sync_redis.hmget(key(:"mean-counts"), *times)
        sync_redis.hmget(key, *times)
      end.each_with_index do |_v, _n|
        _t = times[_n]
        ret[_t] = calculate_value(_v, _t, opts, block)
        _c = ret_counts ? ret_counts[_n] : nil
        ret[_t] = calculate_value(_v, _t, opts, block, _c)
      end
    end
  end

  def calculate_value(_v, _t, opts, block)
    block = @@avg_per_count_proc if average?
    #block = @@count_per_session_proc if unique?
  def calculate_value(_v, _t, opts, block, _c = nil)
    block = @@avg_per_session_proc if unique? && average?

    calc = if block
    calc = if average? && _c
      (_v.to_f / (_c||1).to_i)
    elsif block
      instance_exec(_v, _t, &block)
    else
      _v
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ module FnordMetric::GaugeModifiers
  end

  def incr_avg(gauge, value)
    @redis.incr(gauge.tick_key(time, :"value-count")).callback do
    @redis.hincrby(gauge.key(:"mean-counts"), gauge.tick_at(time), 1).callback do
      incr_tick(gauge, value)
    end
  end
+1 −1
Original line number Diff line number Diff line
module FnordMetric
  VERSION = "1.2.4"
  VERSION = "1.2.5"
end
+5 −5
Original line number Diff line number Diff line
@@ -311,7 +311,7 @@ describe FnordMetric::GaugeModifiers do
    it "should increment_unique a non-progressive gauge" do  
      gauge_key = "fnordmetrics-myns-gauge-mygauge_917-10"    
      @redis.hset(gauge_key, "695280200", "54")
      @redis.set(gauge_key+"-695280200-value-count", 5)
      @redis.hset(gauge_key + "-mean-counts", "695280200", "5")
      create_gauge_context({
        :key => "mygauge_917",
        :average => true,
@@ -323,7 +323,7 @@ describe FnordMetric::GaugeModifiers do
        context.call(event, @redis_wrap, @namespace)
      end
      @redis.hget(gauge_key, "695280200").should == "84"
      @redis.get(gauge_key+"-695280200-value-count").should == "6"
      @redis.hget(gauge_key + "-mean-counts", "695280200").should == "6"
    end

  end