Commit b07aceec2f030c6b2bc3744e2e2f46e5e1af8d8f
Exists in
master
Merge pull request #990 from 8398a7/use_unicorn_worker_killer
add unicorn worker killer
Showing
5 changed files
with
24 additions
and
0 deletions
Show diff stats
.env.default
@@ -23,3 +23,8 @@ GITHUB_API_URL=https://api.github.com | @@ -23,3 +23,8 @@ GITHUB_API_URL=https://api.github.com | ||
23 | GITHUB_ACCESS_SCOPE='[repo]' | 23 | GITHUB_ACCESS_SCOPE='[repo]' |
24 | GITHUB_SITE_TITLE=GitHub | 24 | GITHUB_SITE_TITLE=GitHub |
25 | DEVISE_MODULES='[database_authenticatable,recoverable,rememberable,trackable,validatable,omniauthable]' | 25 | DEVISE_MODULES='[database_authenticatable,recoverable,rememberable,trackable,validatable,omniauthable]' |
26 | +USE_UNICORN_WORKER_KILLER=false | ||
27 | +KILL_ON_REQUEST_COUNT_MIN=3072 | ||
28 | +KILL_ON_REQUEST_COUNT_MAX=4096 | ||
29 | +KILL_ON_RSS_MIN=250 | ||
30 | +KILL_ON_RSS_MAX=300 |
Gemfile
@@ -101,6 +101,7 @@ end | @@ -101,6 +101,7 @@ end | ||
101 | group :heroku, :production do | 101 | group :heroku, :production do |
102 | gem 'rails_12factor', require: ENV.key?("HEROKU") | 102 | gem 'rails_12factor', require: ENV.key?("HEROKU") |
103 | gem 'unicorn', require: false, platform: 'ruby' | 103 | gem 'unicorn', require: false, platform: 'ruby' |
104 | + gem 'unicorn-worker-killer' | ||
104 | end | 105 | end |
105 | 106 | ||
106 | gem 'therubyracer', platform: :ruby # C Ruby (MRI) or Rubinius, but NOT Windows | 107 | gem 'therubyracer', platform: :ruby # C Ruby (MRI) or Rubinius, but NOT Windows |
Gemfile.lock
@@ -134,6 +134,7 @@ GEM | @@ -134,6 +134,7 @@ GEM | ||
134 | multi_json | 134 | multi_json |
135 | font-awesome-rails (4.2.0.0) | 135 | font-awesome-rails (4.2.0.0) |
136 | railties (>= 3.2, < 5.0) | 136 | railties (>= 3.2, < 5.0) |
137 | + get_process_mem (0.2.0) | ||
137 | globalid (0.3.6) | 138 | globalid (0.3.6) |
138 | activesupport (>= 4.1.0) | 139 | activesupport (>= 4.1.0) |
139 | haml (4.0.6) | 140 | haml (4.0.6) |
@@ -401,6 +402,9 @@ GEM | @@ -401,6 +402,9 @@ GEM | ||
401 | kgio (~> 2.6) | 402 | kgio (~> 2.6) |
402 | rack | 403 | rack |
403 | raindrops (~> 0.7) | 404 | raindrops (~> 0.7) |
405 | + unicorn-worker-killer (0.4.3) | ||
406 | + get_process_mem (~> 0) | ||
407 | + unicorn (~> 4) | ||
404 | useragent (0.14.0) | 408 | useragent (0.14.0) |
405 | warden (1.2.3) | 409 | warden (1.2.3) |
406 | rack (>= 1.0) | 410 | rack (>= 1.0) |
@@ -480,6 +484,7 @@ DEPENDENCIES | @@ -480,6 +484,7 @@ DEPENDENCIES | ||
480 | uglifier | 484 | uglifier |
481 | underscore-rails | 485 | underscore-rails |
482 | unicorn | 486 | unicorn |
487 | + unicorn-worker-killer | ||
483 | useragent | 488 | useragent |
484 | xmpp4r | 489 | xmpp4r |
485 | yajl-ruby | 490 | yajl-ruby |
config.ru
1 | +if ENV['USE_UNICORN_WORKER_KILLER'] | ||
2 | + require 'unicorn/worker_killer' | ||
3 | + max_request_min = ENV['KILL_ON_REQUEST_COUNT_MIN'].to_i || 3072 | ||
4 | + max_request_max = ENV['KILL_ON_REQUEST_COUNT_MAX'].to_i || 4096 | ||
5 | + use Unicorn::WorkerKiller::MaxRequests, max_request_min, max_request_max | ||
6 | + oom_min = ((ENV['KILL_ON_RSS_MIN'].to_i || 250) * (1024**2)) | ||
7 | + oom_max = ((ENV['KILL_ON_RSS_MAX'].to_i || 300) * (1024**2)) | ||
8 | + use Unicorn::WorkerKiller::Oom, oom_min, oom_max | ||
9 | +end | ||
10 | + | ||
1 | # This file is used by Rack-based servers to start the application. | 11 | # This file is used by Rack-based servers to start the application. |
2 | 12 | ||
3 | require ::File.expand_path('../config/environment', __FILE__) | 13 | require ::File.expand_path('../config/environment', __FILE__) |
docs/configuration.md
@@ -100,4 +100,7 @@ In order of precedence Errbit uses: | @@ -100,4 +100,7 @@ In order of precedence Errbit uses: | ||
100 | <dt>DEVISE_MODULES | 100 | <dt>DEVISE_MODULES |
101 | <dd>Devise modules to enable | 101 | <dd>Devise modules to enable |
102 | <dd>defaults to [database_authenticatable,recoverable,rememberable,trackable,validatable,omniauthable] | 102 | <dd>defaults to [database_authenticatable,recoverable,rememberable,trackable,validatable,omniauthable] |
103 | +<dt>USE_UNICORN_WORKER_KILLER</dt> | ||
104 | +<dd>unicorn-worker-killer modules to enable</dd> | ||
105 | +<dd>defaults to false</dd> | ||
103 | </dl> | 106 | </dl> |