Better performance with Unicorn on Heroku
I just switched CityDiff to Unicorn on Heroku. The site is using a single free dyno that was originally running Thin.
After the switch to Unicorn, I'm seeing faster response times for AJAX requests and less overall memory usage.
Here is my configuration.
Gemfile
gem "unicorn"
Procfile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
config/unicorn.rb
worker_processes 3
timeout 30
preload_app true
before_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
Rails.logger.info('Disconnected from ActiveRecord')
end
sleep 1
end
after_fork do |server, worker|
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
Rails.logger.info('Connected to ActiveRecord')
end
end
Thanks to railsonfire for the inspiration. http://blog.railsonfire.com/2012/05/06/Unicorn-on-Heroku.html
Written by Nathan Hopkins
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#N
Authors
Related Tags
#n
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#