From the Blogosphere
Unleash the Puma on Heroku
Getting Puma to run on Heroku is easy. You should be able to get everything up and running in minutes. Here is how you do it.
By: Manuel Weiss
Dec. 20, 2013 03:06 PM
18 months ago I wrote a blog post about how to use Unicorn to optimize our Heroku performance. Since then we've been using Unicorn on Heroku.
Over the last couple of months our business grew a lot and Unicorn seemed to take more resources than necessary. We switched to 2X instances and still needed quite a lot of workers.
Although larger Heroku bills were part of our decision to optimize, we mostly felt the quality of our service was diminishing.
We started with Puma as it seemed to be one of the more widely used options. For the last month we have used Puma in production on the Codeship and are happy with it. There are a couple of potential pitfalls, but overall it made our performance better and Heroku bills smaller.
We are still using MRI 2.0.0-p195 on Heroku and haven't switched to either JRuby or Rubinius. Although there is a lot performance we could gain from this switch we are happy with the performance we have and it would make our development more complicated.
We optimized different parts of our application at the same time, so we don't have scientifically valid data for our change from Unicorn to Puma. For example we switched to a Database with more memory on Heroku and changed our auto-reload functionality. All of this combined resulted in a much better performance, but it can't be attributed to Puma alone.
Setting Up Puma on Heroku
Add Puma to Gemfile
Add Puma to Procfile
It also uses bash syntax to define defaults if no environment values are set. Starting several Puma workers allows you to get even more out of your Heroku Dyno.
Setting the values through the Environment helped make it easy to figure out the numbers of workers and threads that work fine. This will be different for every application and you should experiment with it. Currently we use 10 Threads and 2 Workers.
Set DB connections through Environment
view rawdatabase_connections.rb hosted with ❤ by GitHub The ActiveRecord reaper will regularly check your open connections and remove them if they become stale. You can read more about it in the Heroku Docs
Monitor with NewRelic
Make sure your MAX_WORKERS is lower than the DB_POOL_SIZE, otherwise your application might not be able to connect to the database and throw exceptions.
Our assumption is that Unicorn hid this problem before by restarting the workers regularly.
It is very easy to get started and if you feel you could gain better performance definitely give it a try.
As passenger now supports Heroku we might look into it as well sometime in the future. Right now we are happy with Puma though.
Tell us your experience with Puma or other performance optimizations on Heroku in the comments.
Links to get started started
Latest AJAXWorld RIA Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
SYS-CON Featured Whitepapers
Most Read This Week