Skip to content

Instantly share code, notes, and snippets.

@dblock
Created February 16, 2013 16:28
Show Gist options
  • Save dblock/4967551 to your computer and use it in GitHub Desktop.
Save dblock/4967551 to your computer and use it in GitHub Desktop.
Instrument thin to measure wait time inside its internal queue.
module Thin
class Connection < EventMachine::Connection
attr_accessor :init_ts, :data_ts
def initialize
super
@init_ts = Time.now
Gravity.metrics.increment 'thin.connection'
end
alias_method :_receive_data, :receive_data
def receive_data(data)
unless @data_ts
@data_ts = Time.now
wait_time = ((@data_ts - @init_ts) * 1000.0).to_i
Rails.logger.info "Processing request from #{remote_address}, thin.wait_time=#{wait_time}ms"
end
_receive_data(data)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment