class UnicornWrangler::OutOfMemoryKiller

Public Class Methods

new(logger, stats, max: 20, check_every: 250) click to toggle source
Calls superclass method UnicornWrangler::Killer::new
# File lib/unicorn_wrangler.rb, line 146
def initialize(logger, stats, max: 20, check_every: 250)
  super(logger, stats)
  @max = max
  @check_every = check_every
  @logger.info "Killing workers when using more than #{@max}MB"
end

Public Instance Methods

call(requests, request_time) click to toggle source
# File lib/unicorn_wrangler.rb, line 153
def call(requests, request_time)
  return unless (requests % @check_every).zero? # avoid overhead of checking memory too often
  memory = used_memory
  if memory > @max
    kill :memory, memory, requests, request_time
  else
    @stats.histogram("#{STATS_NAMESPACE}.keep.memory", memory) if @stats
    report_status "Keeping", :memory, memory, requests, request_time
  end
end