diff --git a/Gemfile b/Gemfile index ae404d8..0da950b 100644 --- a/Gemfile +++ b/Gemfile @@ -100,8 +100,7 @@ end group :heroku, :production do gem 'rails_12factor', require: ENV.key?("HEROKU") - gem 'unicorn', require: false, platform: 'ruby' - gem 'unicorn-worker-killer' + gem 'puma' end gem 'therubyracer', platform: :ruby # C Ruby (MRI) or Rubinius, but NOT Windows diff --git a/Gemfile.lock b/Gemfile.lock index 8cf2947..1b375e6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -134,7 +134,6 @@ 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) @@ -165,7 +164,6 @@ GEM kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) - kgio (2.9.3) launchy (2.4.3) addressable (~> 2.3) launchy (2.4.3-java) @@ -258,6 +256,7 @@ GEM pry (~> 0.10) pry-rails (0.3.4) pry (>= 0.9.10) + puma (2.15.3) quiet_assets (1.1.0) railties (>= 3.1, < 5.0) rack (1.6.4) @@ -300,7 +299,6 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.0.0) - raindrops (0.13.0) rake (10.4.2) ref (1.0.5) request_store (1.1.0) @@ -398,13 +396,6 @@ GEM unf_ext unf (0.1.4-java) unf_ext (0.0.7.1) - unicorn (4.9.0) - 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) @@ -465,6 +456,7 @@ DEPENDENCIES poltergeist pry-byebug pry-rails + puma quiet_assets rack-ssl rack-ssl-enforcer @@ -483,8 +475,6 @@ DEPENDENCIES timecop uglifier underscore-rails - unicorn - unicorn-worker-killer useragent xmpp4r yajl-ruby diff --git a/Procfile b/Procfile index 8fd8940..e91374b 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: bundle exec unicorn -c ./config/unicorn.default.rb +web: bundle exec puma -C config/puma.default.rb diff --git a/config.ru b/config.ru index bde969b..76d9bb0 100644 --- a/config.ru +++ b/config.ru @@ -1,13 +1,3 @@ -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__) diff --git a/config/puma.default.rb b/config/puma.default.rb new file mode 100644 index 0000000..765116b --- /dev/null +++ b/config/puma.default.rb @@ -0,0 +1,19 @@ +# https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server + +workers Integer(ENV['WEB_CONCURRENCY'] || 2) +threads_count = Integer(ENV['MAX_THREADS'] || 5) +threads threads_count, threads_count + +preload_app! + +rackup DefaultRackup +port ENV['PORT'] || 3000 +environment ENV['RACK_ENV'] || 'development' + +on_worker_boot do + # Worker specific setup for Rails 4.1+ + # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot + ActiveSupport.on_load(:active_record) do + ActiveRecord::Base.establish_connection + end +end diff --git a/config/unicorn.default.rb b/config/unicorn.default.rb deleted file mode 100644 index b97ef26..0000000 --- a/config/unicorn.default.rb +++ /dev/null @@ -1,31 +0,0 @@ -# http://michaelvanrooijen.com/articles/2011/06/01-more-concurrency-on-a-single-heroku-dyno-with-the-new-celadon-cedar-stack/ - -worker_processes 3 # amount of unicorn workers to spin up -timeout 30 # restarts workers that hang for 30 seconds -preload_app true -listen ENV['PORT'] || 8080 -pid ENV['UNICORN_PID'] if ENV['UNICORN_PID'] - -# Taken from github: https://github.com/blog/517-unicorn -# Though everyone uses pretty miuch the same code -before_fork do |server, _worker| - ## - # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and - # immediately start loading up a new version of itself (loaded with a new - # version of our app). When this new Unicorn is completely loaded - # it will begin spawning workers. The first worker spawned will check to - # see if an .oldbin pidfile exists. If so, this means we've just booted up - # a new Unicorn and need to tell the old one that it can now die. To do so - # we send it a QUIT. - # - # Using this method we get 0 downtime deploys. - - old_pid = "#{server.config[:pid]}.oldbin" - if File.exist?(old_pid) && server.pid != old_pid - begin - Process.kill("QUIT", File.read(old_pid).to_i) - rescue Errno::ENOENT, Errno::ESRCH - warn "Unicorn: master process already killed, no problem" - end - end -end -- libgit2 0.21.2