lib/goliath/plugins/latency.rb in goliath-0.9.4 vs lib/goliath/plugins/latency.rb in goliath-1.0.0.beta.1
- old
+ new
@@ -4,10 +4,14 @@
#
# @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
@@ -26,12 +30,12 @@
@@recent_latency
end
# Called automatically to start the plugin
def run
- EM.add_periodic_timer(1) do
- @@recent_latency = (Time.now.to_f - @last)
- @logger.info "LATENCY: #{@@recent_latency}"
+ 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