Skip to content

Instantly share code, notes, and snippets.

@jamiew
Last active October 4, 2015 12:28
Show Gist options
  • Save jamiew/2636487 to your computer and use it in GitHub Desktop.
Save jamiew/2636487 to your computer and use it in GitHub Desktop.
Using unicorn on Heroku
# config/initailizers/newrelic_reconnect.rb
# Ensure the agent is started using Unicorn
# This is needed when using Unicorn and preload_app is NOT set to true.
# https://newrelic.com/docs/ruby/no-data-with-unicorn
NewRelic::Agent.after_fork(:force_reconnect => true) if defined? Unicorn
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
# config/unicorn.rb
# Minimal Heroku unicorn config
# * I found no real gain from enabling preload_app on Heroku (which makes for faster worker starts/restarts),
# and it will cause strange issues if you don't re-establish all connections correctly
# * Heroku has a 30s timeout so we set to 60, allowing them to handle timeouts and issue an H12 error
# * Depending on your memory usage workers can be bumped to 3-4. With Sinatra it can be 8+
worker_processes 3
timeout 60
@jamiew
Copy link
Author

jamiew commented Jan 9, 2013

I've just updated this and increased timeout to >30s timeout, which allows Heroku to handle killing slow workers and issuing an H12. Heroku router errors can be monitored more easily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment