Class: Goliath::Plugin::Latency

Inherits:
Object
  • Object
show all
Defined in:
lib/goliath/plugins/latency.rb

Overview

Report latency information about the EventMachine reactor to the log file.

Examples:

plugin Goliath::Plugin::Latency

Constant Summary collapse

LATENCY_TIMING =

Number of seconds to wait before logging latency

1
@@recent_latency =
0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port, config, status, logger) ⇒ Goliath::Plugin::Latency

Called by the framework to initialize the plugin

Parameters:

  • port (Integer)

    Unused

  • config (Hash)

    The server configuration data

  • status (Hash)

    A status hash

  • logger (Log4R::Logger)

    The logger



20
21
22
23
24
25
26
# File 'lib/goliath/plugins/latency.rb', line 20

def initialize(port, config, status, logger)
  @status = status
  @config = config
  @logger = logger

  @last = Time.now.to_f
end

Class Method Details

.recent_latencyObject



29
30
31
# File 'lib/goliath/plugins/latency.rb', line 29

def self.recent_latency
  @@recent_latency
end

Instance Method Details

#runObject

Called automatically to start the plugin



34
35
36
37
38
39
40
# File 'lib/goliath/plugins/latency.rb', line 34

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