rack_oom_killer 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENCE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2012 Lincoln Stoll <lstoll@lstoll.net>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Rack OOM Killer
2
+
3
+ Post-request, will check the memory usage of the process and if it exceeds the configured amount (default 350m), exit. Try and exit nicely initially, after 10 seconds kill the process
4
+
5
+ ## Usage
6
+
7
+ Rails 3.x:
8
+
9
+ Gemfile:
10
+
11
+ gem "rack_oom_killer"
12
+
13
+ In application.rb
14
+
15
+ # max_mem optional
16
+ config.middleware.use = Rack::OOMKiller, :max_mem => 200
17
+
18
+ Sinatra:
19
+
20
+ Require and load gem as appropriate
21
+
22
+ # max_mem is optional
23
+ use Rack::OOMKiller, :max_mem => 200
24
+
25
+ ## Caveats
26
+
27
+ Note, this executes *after* the request has been processed - if a single request blows out the memory usage too much, this isn't going to handle that.
28
+
29
+ Only tested on Linux and Mac. Highly unlikely to work on Windows.
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class OOMKiller
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ module Rack
2
+ class OOMKiller
3
+ def initialize(app, options={})
4
+ default_options = {
5
+ :max_mem => 350,
6
+ }
7
+ @app, @options = app, default_options.merge(options)
8
+ end
9
+
10
+ def call(env)
11
+ ret = @app.call(env)
12
+ rss_mem = `ps -o rss= -p #{$$}`.to_i
13
+ if rss_mem > @options[:max_mem] * 1024
14
+ puts "Memory usage excedes #{@options[:max_mem]}mb limit, exiting"
15
+ Thread.new do
16
+ `kill -INT #{$$}`
17
+ skeep 10
18
+ `kill -KILL #{$$}`
19
+ end
20
+ end
21
+ ret
22
+ end
23
+ end
24
+ end
@@ -0,0 +1 @@
1
+ require 'rack/oom_killer'
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_oom_killer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lincoln Stoll
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70282461585720 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70282461585720
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack
27
+ requirement: &70282461585260 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70282461585260
36
+ description: Rack::OOMKiller is a rack middleware that will check the memory usage
37
+ of the process post-request, and if > 400mb exit
38
+ email:
39
+ - lstoll@lstoll.net
40
+ executables: []
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - lib/rack/oom_killer/version.rb
45
+ - lib/rack/oom_killer.rb
46
+ - lib/rack_oom_killer.rb
47
+ - LICENCE
48
+ - README.md
49
+ homepage: http://github.com/lstoll/rack_oom_killer
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.6
67
+ requirements: []
68
+ rubyforge_project: rack-ssl-enforcer
69
+ rubygems_version: 1.8.11
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Kills process when using excess memory
73
+ test_files: []