Heroku and Passenger: focus on the app performance

Heroku is an excellent and popular hosting service for web apps. Being a fully hosted service, you will never have to wake up in the morning to blinking lights on your phone, notifying you of text messages and missed calls, as well as a lot of mail, all trying to tell you that your server has been down since 3AM. Combined with its ease of use, it is no wonder that Heroku is becoming more and more popular.

Passenger is an excellent addition to Heroku. By running Passenger on Heroku, you will be able to tune your app for optimal performance at the lowest cost. With our full set of tools: Passenger, Passenger Status Service and Union Station we deliver a complete solution for running, monitoring and optimising your application.

Save time and money with Heroku

Not having to run a dedicated operations team can save you a lot of headaches, time and money. If your developers can focus on the application instead of designing and maintaining a hosting infrastructure 24x7, you will probably make them a lot happier. In my opinion, developing applications and system administration are different skills. If you want to focus on development, consider running Passenger on Heroku. Let Passenger take care of your application and let Heroku maintain the servers. It will save a lot of time and deploying a new application can be done in minutes.

Passenger has been working great for us! We haven't had time optimize it, but the initial settings we choose have it running better than Puma. Thank you again!

Tom O'Neill, Periscope Data

Passenger on Heroku

Heroku allows you to choose the underlying application server with ease. As you can see when you compare the different servers, Passenger has the widest set of features. We have made a number of walkthroughs for different infrastructures and if you follow our Heroku walkthrough, you should be ready to go in minutes. Heroku is a supported platform since 2013 and the experience of our users has been great. With lower memory usage in comparison to other application servers, Passenger allows you to run more workers and have higher performance on Heroku. Multithreading can enhance your performance and help you achieve maximum performance.

Getting more performance with Heroku

Besides easy deployment, scaling is a very important aspect of an application and Heroku has an excellent interface to increase the number of Dynos or changing the type of Dyno. The first step should be to increase the performance per Dyno.

Increasing performance per Dyno

Optimizing your application performance is highly dependent on your application, especially on the amount of memory it uses. With Passenger Enterprise, there are two important settings to tune, the number of workers and the number of threads. If your application is thread-safe, using threads will significantly lower memory usage and increase efficiency.

Step 1: Setting initial number of workers

We suggest you first set the number of workers according to the table below. For most applications these should be safe settings.

Dyno Type Memory CPU/Cores Number of Workers
free, hobby, standard-1x 512MB 1 (shared) 2
standard-2x 1024MB 2 (shared) 4
performance-m 2.5GB 12 10
performance-l 14GB 50 50

Step 2: Passenger status service

To get better insights in the memory usage of applications managed by Passenger, you can use the Passenger status service. This is a free service which provides access to the output of the passenger-status command remotely, which is very useful for managed servers. Especially if you do not have shell-access.

Passenger Status Service
Passenger Status Service in action

As you can see in the image, the application uses circa 16MB of memory (a Ruby application). If you have a Rails application, memory usage will probably be 200MB+ per worker.

Step 3: Determining workers and threads

Once you know how much memory your application uses approximately, you can calculate values for workers and threads. Follow our optimisation guide to calculate your values for workers and threads.

Step 4: Tune and optimise

After setting workers and threads, verify memory usage of your application and tune until you have optimal performance on your Dyno or are satisfied with the performance. Always make sure to have some headroom to avoid swap usage.

Scaling up Dynos

One of the key benefits of Heroku is that you can scale horizontally very easily by adding more Dynos and you can scale vertically by providing your workers with more memory and cpu-share. This can be done from the command-line or dashboard. A better solution for scaling is to auto-scale your Dynos depending on metrics of your choice.

Hirefire

An application that can take care of the scaling for you is Hirefire. It has a lot of features and can shut down dynos dynamically to avoid wasting money on idle resources.
Hirefire was designed to assist Heroku users with dynamic scaling; try it yourself with their free trial period. Most applications have a changing workload during the day and will benefit from Hirefire or a comparable service.
Hirefire

Monitoring performance: Union Station

Once you have deployed your application successfully to Heroku, it is important to keep an eye on the performance and potential exceptions. Passenger has an integrated solution for application monitoring and analytics: Union Station.

Union Station application performance monitoring

Union Station helps you monitor application response times, cpu-load, memory pressure and exceptions at a glance, as well as all the way down to individual requests. This allows for detailed insights into the performance of the application, as well as whether your users are experiencing application exceptions.

Usage and customer experience

We have gotten a lot of positive feedback of running Passenger on Heroku.

Curious about Passenger, our Passenger Status Service or Union Station? Check them out!

comments powered by Disqus