diff --git a/Gemfile b/Gemfile index 290b83686..0445370c9 100644 --- a/Gemfile +++ b/Gemfile @@ -69,8 +69,8 @@ end group :production do gem 'newrelic_rpm' - # gem 'unicorn-worker-killer' - # gem 'gctools', :platforms => :ruby + gem 'unicorn-worker-killer' + gem 'gctools', :platforms => :ruby end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 81a1c6c7a..d45548395 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -138,6 +138,8 @@ GEM multipart-post (>= 1.2, < 3) ffaker (2.1.0) ffi (1.9.10-x64-mingw32) + gctools (0.2.4) + get_process_mem (0.2.1) git (1.3.0) github_api (0.14.5) addressable (~> 2.4.0) @@ -401,6 +403,9 @@ GEM kgio (~> 2.6) rack raindrops (~> 0.7) + unicorn-worker-killer (0.4.4) + get_process_mem (~> 0) + unicorn (>= 4, < 6) vcr (2.9.3) webmock (1.21.0) addressable (>= 2.3.6) @@ -435,6 +440,7 @@ DEPENDENCIES dtext_rb! factory_girl ffaker + gctools google-api-client highline kgio @@ -472,6 +478,7 @@ DEPENDENCIES tzinfo-data uglifier unicorn + unicorn-worker-killer vcr webmock whenever diff --git a/config.ru b/config.ru index ad365710b..7d1a02e2f 100644 --- a/config.ru +++ b/config.ru @@ -2,9 +2,18 @@ require ::File.expand_path('../config/environment', __FILE__) -# if defined?(Unicorn) && Rails.env.production? -# require_dependency 'gctools/oobgc' -# use GC::OOB::UnicornMiddleware -# end +if defined?(Unicorn) && Rails.env.production? + # Unicorn self-process killer + require 'unicorn/worker_killer' + + # Max requests per worker + use Unicorn::WorkerKiller::MaxRequests, 10_000, 15_000 + + # Max memory size (RSS) per worker + #use Unicorn::WorkerKiller::Oom, (192*(1024**2)), (256*(1024**2)) + + require 'gctools/oobgc' + use GC::OOB::UnicornMiddleware +end run Rails.application