Build Robust & Production Quality Applications - Lesson 6: Riding Unicorns
20 May 2015Using Unicorn as a Production Server
Visit http://devcenter.heroku.com/articles/rails-unicorn
The issue with the rails server, is that it only allows for one web process at a time. Unicorn allows you to add additional servers, which can be specified in your config/unicorn.rb file
1. Add the Unicorn gem to your gemfile
gem 'unicorn'
then, run bundle install
2. Config
This is where you define the number worker processes. Worker processes in this context is all processes not just background processes. Below indicates that we want three worker processes running at once.
#config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
Update your Procfile
Set Unicorn as the server for the web process in your Procfile:
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
Adding Unicorn to your Heroku App
1. Add Redis to go
heroku addons:create redistogo
2. Run the following for Sidekiq version 3.0 or later:
heroku config:set REDISPROVIDER=REDISTOGOURL
3 Free background job on Heroku
Running more than 1 dyno (server) on Heroku costs, and ain't nobody got time for that. Coderwall has created a hack: