Add unicorn worker killer

[ci skip]
This commit is contained in:
Oliver Günther
2016-11-02 10:28:02 +01:00
parent 13dcc92b56
commit 025f0cdff4
3 changed files with 25 additions and 0 deletions
+3
View File
@@ -126,6 +126,9 @@ group :production do
# requires memcached 1.4+
# see https://github.clientom/mperham/dalli
gem 'dalli', '~> 2.7.6'
# Unicorn worker killer to restart unicorn child workers
gem 'unicorn-worker-killer', require: false
end
gem 'sprockets', '~> 3.7.0'
+5
View File
@@ -288,6 +288,7 @@ GEM
fuubar (2.2.0)
rspec-core (~> 3.0)
ruby-progressbar (~> 1.4)
get_process_mem (0.2.1)
gherkin (4.0.0)
globalid (0.3.7)
activesupport (>= 4.1.0)
@@ -560,6 +561,9 @@ GEM
unicorn (5.1.0)
kgio (~> 2.6)
raindrops (~> 0.7)
unicorn-worker-killer (0.4.4)
get_process_mem (~> 0)
unicorn (>= 4, < 6)
url (0.3.2)
virtus (1.0.5)
axiom-types (~> 0.1)
@@ -698,6 +702,7 @@ DEPENDENCIES
transactional_lock!
tzinfo-data (~> 1.2016.1)
unicorn
unicorn-worker-killer
warden (~> 1.2)
warden-basic_auth (~> 0.2.1)
webmock (~> 2.1.0)
+17
View File
@@ -31,6 +31,23 @@
require ::File.expand_path('../config/environment', __FILE__)
##
# Use the worker killer when Unicorn is being used
if defined?(Unicorn) && Rails.env.production?
require 'unicorn/worker_killer'
min_ram = ENV.fetch('OPENPROJECT_UNICORN_RAM2KILL_MIN', 340 * 1 << 20).to_i
max_ram = ENV.fetch('OPENPROJECT_UNICORN_RAM2KILL_MAX', 400 * 1 << 20).to_i
min_req = ENV.fetch('OPENPROJECT_UNICORN_REQ2KILL_MIN', 3072).to_i
max_req = ENV.fetch('OPENPROJECT_UNICORN_REQ2KILL_MAX', 4096).to_i
# Kill Workers randomly between 340 and 400 MB (per default)
# or between 3072 and 4096 requests.
# Our largest installations are starting around 200/230 MB
use Unicorn::WorkerKiller::Oom, min_ram, max_ram
use Unicorn::WorkerKiller::MaxRequests, min_req, max_req
end
##
# Returns true if the application should be run under a subdirectory.
def map_subdir?