If you have deployed a lot of applications to Heroku you may have noticed that on the first page load of your site it takes an EXTREMELY long time to load your page. This is consistent whether you are the first person to hit your domain today, tomorrow or next week.

So why is this? Well when you are on Heroku's free plan they do what is called Dyno Idling. What this means is that when your web dyno is not in direct use they will idle your dynos and spin them back up when someone requests the page for the first time. 

For more information about how Heroku actually works Dan Kaufman wrote an amazing talk about scaling your dynos.

This should sound a lot like the sad user who gets the initial page load of a cached website. So to fix this we have one of two options. 

The first is to use Pingdom and have them ping your site every 5 minutes to ensure it is still up. This is an AMAZING service that can actually monitor your application and tell you that Heroku is doing what they are meant to.

While this is great, once you get above one application it starts to cost a considerable amount of money so why not use another one of Heroku's free services to do this for me?

Enter Heroku scheduler. What this allows you to do is run a rake task every 5 minutes of your choosing. So I wrote a rake task that simply makes a get request to my sites home page to make sure that my application is always working. See the gist below on implementation detail. 


comments powered by Disqus

Mike Silvis

Mikesilvis