Class: UnicornKiller::Oom

Inherits:
Object
  • Object
show all
Includes:
Kill
Defined in:
lib/unicorn_killer.rb

Instance Method Summary collapse

Methods included from Kill

#quit

Constructor Details

#initialize(app, memory_size = 512 * 1024, check_cycle = 10) ⇒ Oom


18
19
20
21
22
23
# File 'lib/unicorn_killer.rb', line 18

def initialize(app, memory_size= 512 * 1024, check_cycle = 10)
  @app = app
  @memory_size = memory_size
  @check_cycle = check_cycle
  @check_count = 0
end

Instance Method Details

#call(env) ⇒ Object


29
30
31
32
33
34
35
36
# File 'lib/unicorn_killer.rb', line 29

def call(env)
  @process_start ||= Time.now
  if (@check_count += 1) % @check_cycle == 0
    @check_count = 0
    quit if rss > @memory_size
  end
  @app.call env
end

#rssObject


25
26
27
# File 'lib/unicorn_killer.rb', line 25

def rss
  `ps -o rss= -p #{Process.pid}`.to_i
end