Commit 5045ebe2e0b5fbc5732128a7e6df80dd8b662fbc
1 parent
9d51326c
Exists in
master
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 | 23 | GITHUB_ACCESS_SCOPE='[repo]' |
| 24 | 24 | GITHUB_SITE_TITLE=GitHub |
| 25 | 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 | 101 | group :heroku, :production do |
| 102 | 102 | gem 'rails_12factor', require: ENV.key?("HEROKU") |
| 103 | 103 | gem 'unicorn', require: false, platform: 'ruby' |
| 104 | + gem 'unicorn-worker-killer' | |
| 104 | 105 | end |
| 105 | 106 | |
| 106 | 107 | gem 'therubyracer', :platform => :ruby # C Ruby (MRI) or Rubinius, but NOT Windows | ... | ... |
Gemfile.lock
| ... | ... | @@ -134,6 +134,7 @@ GEM |
| 134 | 134 | multi_json |
| 135 | 135 | font-awesome-rails (4.2.0.0) |
| 136 | 136 | railties (>= 3.2, < 5.0) |
| 137 | + get_process_mem (0.2.0) | |
| 137 | 138 | globalid (0.3.6) |
| 138 | 139 | activesupport (>= 4.1.0) |
| 139 | 140 | haml (4.0.6) |
| ... | ... | @@ -401,6 +402,9 @@ GEM |
| 401 | 402 | kgio (~> 2.6) |
| 402 | 403 | rack |
| 403 | 404 | raindrops (~> 0.7) |
| 405 | + unicorn-worker-killer (0.4.3) | |
| 406 | + get_process_mem (~> 0) | |
| 407 | + unicorn (~> 4) | |
| 404 | 408 | useragent (0.14.0) |
| 405 | 409 | warden (1.2.3) |
| 406 | 410 | rack (>= 1.0) |
| ... | ... | @@ -480,6 +484,7 @@ DEPENDENCIES |
| 480 | 484 | uglifier |
| 481 | 485 | underscore-rails |
| 482 | 486 | unicorn |
| 487 | + unicorn-worker-killer | |
| 483 | 488 | useragent |
| 484 | 489 | xmpp4r |
| 485 | 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 | 11 | # This file is used by Rack-based servers to start the application. |
| 2 | 12 | |
| 3 | 13 | require ::File.expand_path('../config/environment', __FILE__) | ... | ... |
docs/configuration.md
| ... | ... | @@ -100,4 +100,7 @@ In order of precedence Errbit uses: |
| 100 | 100 | <dt>DEVISE_MODULES |
| 101 | 101 | <dd>Devise modules to enable |
| 102 | 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 | 106 | </dl> | ... | ... |