Skip to content

Commit

Permalink
Don't let puma preload the app if there's only one worker process
Browse files Browse the repository at this point in the history
It seems like some race condition causes one or both of the worker
processes to be wedged on start. This can manifest after a deploy,
or when Heroku does its daily dyno restart. The puma config now
specifies not to `preload_app!` if there's only one worker process,
because it provides no memory benefit in that situation anyway.

We may need to revisit this decision if we ever start actually
running more than one worker on each dyno.

Decrease Rack::Timeout timeout to 20 seconds
  • Loading branch information
tjgrathwell committed Sep 6, 2015
1 parent 028c71a commit 62450d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/initializers/timeout.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if Rails.env.production?
Rack::Timeout.timeout = 25 # seconds
Rack::Timeout.timeout = 20 # seconds
end
17 changes: 11 additions & 6 deletions config/puma.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
worker_count = Integer(ENV['WEB_CONCURRENCY'] || 2)
workers worker_count
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!
unless worker_count == 1
preload_app!
end

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
ActiveRecord::Base.establish_connection
unless worker_count == 1
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
ActiveRecord::Base.establish_connection
end
end

0 comments on commit 62450d2

Please sign in to comment.