Skip to content

Commit

Permalink
Merge pull request #990 from 8398a7/use_unicorn_worker_killer
Browse files Browse the repository at this point in the history
add unicorn worker killer
  • Loading branch information
stevecrozz committed Nov 23, 2015
2 parents c5393af + 5045ebe commit b07acee
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.default
Expand Up @@ -23,3 +23,8 @@ GITHUB_API_URL=https://api.github.com
GITHUB_ACCESS_SCOPE='[repo]'
GITHUB_SITE_TITLE=GitHub
DEVISE_MODULES='[database_authenticatable,recoverable,rememberable,trackable,validatable,omniauthable]'
USE_UNICORN_WORKER_KILLER=false
KILL_ON_REQUEST_COUNT_MIN=3072
KILL_ON_REQUEST_COUNT_MAX=4096
KILL_ON_RSS_MIN=250
KILL_ON_RSS_MAX=300
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -101,6 +101,7 @@ end
group :heroku, :production do
gem 'rails_12factor', require: ENV.key?("HEROKU")
gem 'unicorn', require: false, platform: 'ruby'
gem 'unicorn-worker-killer'
end

gem 'therubyracer', platform: :ruby # C Ruby (MRI) or Rubinius, but NOT Windows
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Expand Up @@ -134,6 +134,7 @@ GEM
multi_json
font-awesome-rails (4.2.0.0)
railties (>= 3.2, < 5.0)
get_process_mem (0.2.0)
globalid (0.3.6)
activesupport (>= 4.1.0)
haml (4.0.6)
Expand Down Expand Up @@ -401,6 +402,9 @@ GEM
kgio (~> 2.6)
rack
raindrops (~> 0.7)
unicorn-worker-killer (0.4.3)
get_process_mem (~> 0)
unicorn (~> 4)
useragent (0.14.0)
warden (1.2.3)
rack (>= 1.0)
Expand Down Expand Up @@ -480,6 +484,7 @@ DEPENDENCIES
uglifier
underscore-rails
unicorn
unicorn-worker-killer
useragent
xmpp4r
yajl-ruby
Expand Down
10 changes: 10 additions & 0 deletions config.ru
@@ -1,3 +1,13 @@
if ENV['USE_UNICORN_WORKER_KILLER']
require 'unicorn/worker_killer'
max_request_min = ENV['KILL_ON_REQUEST_COUNT_MIN'].to_i || 3072
max_request_max = ENV['KILL_ON_REQUEST_COUNT_MAX'].to_i || 4096
use Unicorn::WorkerKiller::MaxRequests, max_request_min, max_request_max
oom_min = ((ENV['KILL_ON_RSS_MIN'].to_i || 250) * (1024**2))
oom_max = ((ENV['KILL_ON_RSS_MAX'].to_i || 300) * (1024**2))
use Unicorn::WorkerKiller::Oom, oom_min, oom_max
end

# This file is used by Rack-based servers to start the application.

require ::File.expand_path('../config/environment', __FILE__)
Expand Down
3 changes: 3 additions & 0 deletions docs/configuration.md
Expand Up @@ -100,4 +100,7 @@ In order of precedence Errbit uses:
<dt>DEVISE_MODULES
<dd>Devise modules to enable
<dd>defaults to [database_authenticatable,recoverable,rememberable,trackable,validatable,omniauthable]
<dt>USE_UNICORN_WORKER_KILLER</dt>
<dd>unicorn-worker-killer modules to enable</dd>
<dd>defaults to false</dd>
</dl>

0 comments on commit b07acee

Please sign in to comment.