Module: Unicorn::WorkerKiller::Oom::MonkeyPatch

Defined in:
lib/unicorn/worker-killer-2/oom.rb

Instance Method Summary collapse

Instance Method Details

#process_client(client) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/unicorn/worker-killer-2/oom.rb', line 9

def process_client(client)
  super(client) # Unicorn::HttpServer#process_client

  return if @_worker_memory_limit_min.zero? &&
            @_worker_memory_limit_max.zero?

  @_worker_check_count ||= 0
  @_worker_check_count += 1

  return unless (@_worker_check_count % @_worker_check_cycle).zero?

  rss = GetProcessMem.new.bytes
  logger.info "#{self}: worker (pid: #{Process.pid}) using #{rss} bytes." if @_verbose
  return if rss < @_worker_memory_limit

  logger.warn "#{self}: worker (pid: #{Process.pid}) exceeds memory limit (#{rss} bytes > #{@_worker_memory_limit} bytes)"
  WorkerKiller.kill_self(logger, @_worker_process_start)
end