Commit 430975149806ec08857547151bda241afa5eba98
1 parent
8c105794
Exists in
master
Unicorn replaced with puma
unicorn gem and configs have been replaced with puma configs found on https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server
Showing
6 changed files
with
23 additions
and
56 deletions
Show diff stats
Gemfile
| @@ -100,8 +100,7 @@ end | @@ -100,8 +100,7 @@ end | ||
| 100 | 100 | ||
| 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' | ||
| 104 | - gem 'unicorn-worker-killer' | 103 | + gem 'puma' |
| 105 | end | 104 | end |
| 106 | 105 | ||
| 107 | gem 'therubyracer', platform: :ruby # C Ruby (MRI) or Rubinius, but NOT Windows | 106 | gem 'therubyracer', platform: :ruby # C Ruby (MRI) or Rubinius, but NOT Windows |
Gemfile.lock
| @@ -134,7 +134,6 @@ GEM | @@ -134,7 +134,6 @@ 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) | ||
| 138 | globalid (0.3.6) | 137 | globalid (0.3.6) |
| 139 | activesupport (>= 4.1.0) | 138 | activesupport (>= 4.1.0) |
| 140 | haml (4.0.6) | 139 | haml (4.0.6) |
| @@ -165,7 +164,6 @@ GEM | @@ -165,7 +164,6 @@ GEM | ||
| 165 | kaminari (0.16.3) | 164 | kaminari (0.16.3) |
| 166 | actionpack (>= 3.0.0) | 165 | actionpack (>= 3.0.0) |
| 167 | activesupport (>= 3.0.0) | 166 | activesupport (>= 3.0.0) |
| 168 | - kgio (2.9.3) | ||
| 169 | launchy (2.4.3) | 167 | launchy (2.4.3) |
| 170 | addressable (~> 2.3) | 168 | addressable (~> 2.3) |
| 171 | launchy (2.4.3-java) | 169 | launchy (2.4.3-java) |
| @@ -258,6 +256,7 @@ GEM | @@ -258,6 +256,7 @@ GEM | ||
| 258 | pry (~> 0.10) | 256 | pry (~> 0.10) |
| 259 | pry-rails (0.3.4) | 257 | pry-rails (0.3.4) |
| 260 | pry (>= 0.9.10) | 258 | pry (>= 0.9.10) |
| 259 | + puma (2.15.3) | ||
| 261 | quiet_assets (1.1.0) | 260 | quiet_assets (1.1.0) |
| 262 | railties (>= 3.1, < 5.0) | 261 | railties (>= 3.1, < 5.0) |
| 263 | rack (1.6.4) | 262 | rack (1.6.4) |
| @@ -300,7 +299,6 @@ GEM | @@ -300,7 +299,6 @@ GEM | ||
| 300 | rake (>= 0.8.7) | 299 | rake (>= 0.8.7) |
| 301 | thor (>= 0.18.1, < 2.0) | 300 | thor (>= 0.18.1, < 2.0) |
| 302 | rainbow (2.0.0) | 301 | rainbow (2.0.0) |
| 303 | - raindrops (0.13.0) | ||
| 304 | rake (10.4.2) | 302 | rake (10.4.2) |
| 305 | ref (1.0.5) | 303 | ref (1.0.5) |
| 306 | request_store (1.1.0) | 304 | request_store (1.1.0) |
| @@ -398,13 +396,6 @@ GEM | @@ -398,13 +396,6 @@ GEM | ||
| 398 | unf_ext | 396 | unf_ext |
| 399 | unf (0.1.4-java) | 397 | unf (0.1.4-java) |
| 400 | unf_ext (0.0.7.1) | 398 | unf_ext (0.0.7.1) |
| 401 | - unicorn (4.9.0) | ||
| 402 | - kgio (~> 2.6) | ||
| 403 | - rack | ||
| 404 | - raindrops (~> 0.7) | ||
| 405 | - unicorn-worker-killer (0.4.3) | ||
| 406 | - get_process_mem (~> 0) | ||
| 407 | - unicorn (~> 4) | ||
| 408 | useragent (0.14.0) | 399 | useragent (0.14.0) |
| 409 | warden (1.2.3) | 400 | warden (1.2.3) |
| 410 | rack (>= 1.0) | 401 | rack (>= 1.0) |
| @@ -465,6 +456,7 @@ DEPENDENCIES | @@ -465,6 +456,7 @@ DEPENDENCIES | ||
| 465 | poltergeist | 456 | poltergeist |
| 466 | pry-byebug | 457 | pry-byebug |
| 467 | pry-rails | 458 | pry-rails |
| 459 | + puma | ||
| 468 | quiet_assets | 460 | quiet_assets |
| 469 | rack-ssl | 461 | rack-ssl |
| 470 | rack-ssl-enforcer | 462 | rack-ssl-enforcer |
| @@ -483,8 +475,6 @@ DEPENDENCIES | @@ -483,8 +475,6 @@ DEPENDENCIES | ||
| 483 | timecop | 475 | timecop |
| 484 | uglifier | 476 | uglifier |
| 485 | underscore-rails | 477 | underscore-rails |
| 486 | - unicorn | ||
| 487 | - unicorn-worker-killer | ||
| 488 | useragent | 478 | useragent |
| 489 | xmpp4r | 479 | xmpp4r |
| 490 | yajl-ruby | 480 | yajl-ruby |
Procfile
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 | - | ||
| 11 | # This file is used by Rack-based servers to start the application. | 1 | # This file is used by Rack-based servers to start the application. |
| 12 | 2 | ||
| 13 | require ::File.expand_path('../config/environment', __FILE__) | 3 | require ::File.expand_path('../config/environment', __FILE__) |
| @@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
| 1 | +# https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server | ||
| 2 | + | ||
| 3 | +workers Integer(ENV['WEB_CONCURRENCY'] || 2) | ||
| 4 | +threads_count = Integer(ENV['MAX_THREADS'] || 5) | ||
| 5 | +threads threads_count, threads_count | ||
| 6 | + | ||
| 7 | +preload_app! | ||
| 8 | + | ||
| 9 | +rackup DefaultRackup | ||
| 10 | +port ENV['PORT'] || 3000 | ||
| 11 | +environment ENV['RACK_ENV'] || 'development' | ||
| 12 | + | ||
| 13 | +on_worker_boot do | ||
| 14 | + # Worker specific setup for Rails 4.1+ | ||
| 15 | + # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot | ||
| 16 | + ActiveSupport.on_load(:active_record) do | ||
| 17 | + ActiveRecord::Base.establish_connection | ||
| 18 | + end | ||
| 19 | +end |
config/unicorn.default.rb
| @@ -1,31 +0,0 @@ | @@ -1,31 +0,0 @@ | ||
| 1 | -# http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/ | ||
| 2 | - | ||
| 3 | -worker_processes 3 # amount of unicorn workers to spin up | ||
| 4 | -timeout 30 # restarts workers that hang for 30 seconds | ||
| 5 | -preload_app true | ||
| 6 | -listen ENV['PORT'] || 8080 | ||
| 7 | -pid ENV['UNICORN_PID'] if ENV['UNICORN_PID'] | ||
| 8 | - | ||
| 9 | -# Taken from github: https://github.com/blog/517-unicorn | ||
| 10 | -# Though everyone uses pretty miuch the same code | ||
| 11 | -before_fork do |server, _worker| | ||
| 12 | - ## | ||
| 13 | - # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and | ||
| 14 | - # immediately start loading up a new version of itself (loaded with a new | ||
| 15 | - # version of our app). When this new Unicorn is completely loaded | ||
| 16 | - # it will begin spawning workers. The first worker spawned will check to | ||
| 17 | - # see if an .oldbin pidfile exists. If so, this means we've just booted up | ||
| 18 | - # a new Unicorn and need to tell the old one that it can now die. To do so | ||
| 19 | - # we send it a QUIT. | ||
| 20 | - # | ||
| 21 | - # Using this method we get 0 downtime deploys. | ||
| 22 | - | ||
| 23 | - old_pid = "#{server.config[:pid]}.oldbin" | ||
| 24 | - if File.exist?(old_pid) && server.pid != old_pid | ||
| 25 | - begin | ||
| 26 | - Process.kill("QUIT", File.read(old_pid).to_i) | ||
| 27 | - rescue Errno::ENOENT, Errno::ESRCH | ||
| 28 | - warn "Unicorn: master process already killed, no problem" | ||
| 29 | - end | ||
| 30 | - end | ||
| 31 | -end |