Module: Unicorn::WorkerKiller::MaxRequests

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

Defined Under Namespace

Modules: MonkeyPatch

Class Method Summary collapse

Class Method Details

.monkey_patch(opts = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/unicorn/worker-killer-2/max_requests.rb', line 23

def self.monkey_patch(opts = {})
  min = opts[:max_requests_min] || 3072
  max = opts[:max_requests_max] || 4096
  verbose = opts[:verbose] || false

  ObjectSpace.each_object(HttpServer) do |s|
    s.extend(MonkeyPatch)

    s.instance_variable_set(:@_worker_process_start, WorkerKiller.now)

    s.instance_variable_set(:@_worker_max_requests_min, min)
    s.instance_variable_set(:@_worker_max_requests_max, max)
    s.instance_variable_set(:@_verbose, verbose)

    r = WorkerKiller.randomize(max - min + 1)
    s.instance_variable_set(:@_worker_request_limit, min + r)
  end
end