Class: Rack::OOMKiller
- Inherits:
-
Object
- Object
- Rack::OOMKiller
- Defined in:
- lib/rack/oom_killer.rb,
lib/rack/oom_killer/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ OOMKiller
constructor
A new instance of OOMKiller.
Constructor Details
#initialize(app, options = {}) ⇒ OOMKiller
Returns a new instance of OOMKiller.
3 4 5 6 7 8 |
# File 'lib/rack/oom_killer.rb', line 3 def initialize(app, ={}) = { :max_mem => 350, } @app, @options = app, .merge() end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rack/oom_killer.rb', line 10 def call(env) ret = @app.call(env) rss_mem = `ps -o rss= -p #{$$}`.to_i if rss_mem > @options[:max_mem] * 1024 puts "Memory usage excedes #{@options[:max_mem]}mb limit, exiting" Thread.new do `kill -INT #{$$}` sleep 10 `kill -KILL #{$$}` end end ret end |