Sha256: 129516f96c3de2ca8ba520065d98790b2a2363f04526faa099a5e6c815fce634

Contents?: true

Size: 1.19 KB

Versions: 9

Compression:

Stored size: 1.19 KB

Contents

module Goliath
  module Plugin
    # Report latency information about the EventMachine reactor to the log file.
    #
    # @example
    #  plugin Goliath::Plugin::Latency
    #
    class Latency
      
      # Number of seconds to wait before logging latency
      LATENCY_TIMING = 1
      
      # Called by the framework to initialize the plugin
      #
      # @param port [Integer] Unused
      # @param config [Hash] The server configuration data
      # @param status [Hash] A status hash
      # @param logger [Log4R::Logger] The logger
      # @return [Goliath::Plugin::Latency] An instance of the Goliath::Plugin::Latency plugin
      def initialize(port, config, status, logger)
        @status = status
        @config = config
        @logger = logger

        @last = Time.now.to_f
      end

      @@recent_latency = 0
      def self.recent_latency
        @@recent_latency
      end

      # Called automatically to start the plugin
      def run
        EM.add_periodic_timer(LATENCY_TIMING) do
          @@recent_latency = ((Time.now.to_f - @last) - LATENCY_TIMING)
          @logger.info "LATENCY: #{(@@recent_latency * 1000)} ms"
          @last = Time.now.to_f
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
goliath-1.0.7 lib/goliath/plugins/latency.rb
goliath-1.0.6 lib/goliath/plugins/latency.rb
goliath-1.0.5 lib/goliath/plugins/latency.rb
goliath-1.0.4 lib/goliath/plugins/latency.rb
goliath-1.0.3 lib/goliath/plugins/latency.rb
goliath-1.0.2 lib/goliath/plugins/latency.rb
goliath-1.0.1 lib/goliath/plugins/latency.rb
goliath-1.0.0 lib/goliath/plugins/latency.rb
goliath-1.0.0.beta.1 lib/goliath/plugins/latency.rb