class UnicornWrangler::Killer

Public Class Methods

new(logger, stats) click to toggle source
# File lib/unicorn_wrangler.rb, line 110
def initialize(logger, stats)
  @logger = logger
  @stats = stats
  @rss_reader = RssReader.new(logger: logger)
end

Private Instance Methods

kill(reason, memory, requests, request_time) click to toggle source

Kills the server, thereby resetting @requests / @request_time in the UnicornWrangler

Possible issue: kill_worker is not meant to kill the server pid … might have strange side effects

# File lib/unicorn_wrangler.rb, line 121
def kill(reason, memory, requests, request_time)
  if @stats
    @stats.increment("#{STATS_NAMESPACE}.killed", tags: ["reason:#{reason}"])

    @stats.histogram("#{STATS_NAMESPACE}.kill.memory", memory)
    @stats.histogram("#{STATS_NAMESPACE}.kill.total_requests", requests)
    @stats.histogram("#{STATS_NAMESPACE}.kill.total_request_time", request_time)
  end

  report_status "Killing", reason, memory, requests, request_time, :warn

  UnicornWrangler.kill_worker
end
report_status(status, reason, memory, requests, request_time, log_level = :debug) click to toggle source
# File lib/unicorn_wrangler.rb, line 140
def report_status(status, reason, memory, requests, request_time, log_level = :debug)
  @logger.send log_level, "#{status} unicorn worker ##{Process.pid} for #{reason}. Requests: #{requests}, Time: #{request_time}, Memory: #{memory}MB"
end
used_memory() click to toggle source

RSS memory in MB. Can be expensive, do not run on every request

# File lib/unicorn_wrangler.rb, line 136
def used_memory
  @rss_reader.rss
end