Monday, 13 February 2012

Keeping Heroku Awake

As an avid fan of Heroku I've used it to host many websites, from very simple ones with a low amount of visits to very complex applications with a large amount of traffic.

However if you are creating your first website with Heroku you may run into a problem. Heroku uses 'Dynos' to run your website, think of them much like a single processor. The more dynos you have the more processing power you have at your disposal. With Heroku you get 1 months worth of a single dyno use for free.

The problem comes when no one has visited  your site for an hour. After an hour your dyno will shut down to save Heroku's resources. If someone then visits your site it will take 5-10 seconds to spool up the dyno and get it serving the users requests. This obviously causes a delay which as us web developers know, any unnecessary delays are unacceptable. Speed matters.

How to get around this?

The best way around this is to keep your Heroku app awake. For this I used the  Heroku scheduler add-on:

This works much like a Cron Jobs but has a few additional features.

First, add Heroku Scheduler to your desired app. Then go to the admin for that application and enter the Heroku Scheduler management area from the 'Add-on' drop down menu

This screen is where we manage what tasks to run and when. I've called this task 'Call_page' as it will be simply calling our heroku app's index page. We will schedule it to run once an hour to keep the app alive.

We now need to add in the code for this task:

Make a new file called 'scheduler.rake' in app/lib/tasks

Within this page put your code:

desc "This task is called by the Heroku cron add-on"
task :call_page => :environment do
   uri = URI.parse('')

As you can see this is a fairly simple bit of code that simply calls your page.

That's all! Your app will now stay awake.

Is it free? 

Most likely yes, with each Heroku app you receive 450 free hours of dyno time each month. As 1 dyno is always running this will leave you with a few hours of free dyno time each month. Heroku charges $0.05 per hour per dyno pro-rated to the nearest second. As this task takes around 5 seconds of dyno worker time that's 2 minutes per day, 14 minutes a week and 1 hour per month. Easily within your allowance.

Beo is a London based Ruby on Rails development company. Find us at


  1. This post has caused a healthy debate about the morality of such actions over at the Heroku google group. Take a look:

    1. Great Article IoT Projects for Students

      Deep Learning Projects for Final Year

      JavaScript Training in Chennai

      JavaScript Training in Chennai

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. thanks for sharing such a informative article ror application development

  3. Will these GET requests distort your site's metrics? For example, mixpanel, split-testing gems, or google analytics? Is it worth creating a special route (or just pinging a nonexistent one)?

  4. Thanks for this.

    You can remove ` => :environment` and instead just do `require "net/http"` at the top of the file.

    This avoids loading the entire Rails environment (can take several seconds for large apps) when you don't need to.

  5. I Really like your good infomation,Thanks
    and please keep sharing it with us.
    Visit us:
    Web Designers London
    Website Design London

  6. I am happy to find this post very useful for me
    The place to play all unblocked games 77 online. Here you can find every blocked games such as: unblockedgames , unblocked games happy , unblocked games 77 , Gmod Free

  7. I Really like your good infomation,Thanks and please keep sharing it with us Pirate Kings banana kong

  8. Com mais de 100 milhões de fãs, o Photo Grid é o criador de colagens fotográficas mais popular do mercado. Baixar Photo Grid para o conforto da máquina inovadora. Photo Grid baixar - download Photo Grid - Photo Grid gratis - Photo Grid - baixar Photo Grid - Photo Grid baixar

  9. I'm puzzled with lots of exercises. I was afraid I could not do the right time despite my hard work. I need a support person.

  10. Thanks for sharing the information. It is very useful for my future. keep sharing

  11. I was very impressed by this post, this site has always been pleasant news. Thank you very much for such an interesting post. Keep working, great job! In my free time, I like play game: What about you?

  12. game is so fun, you try?

  13. I understand what you bring it very meaningful and useful, thanks.

  14. There are things I can not understand but I will learn it. I think nothing is too late. Then I realized that I had improved a lot.

  15. I know there will be many difficulties and challenges but I am determined to do it. If it does not succeed then it will be a lesson for me as well

  16. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
    Very interesting blog.

  17. İnstagram takipçi satın al! İnstagram takipçi sitesi ile takipçi satın al sende sosyal medyada fenomen olmaya bir adım at. Sende hemen instagram takipçi satın almak istiyorsan tıkla:

    1- takipçi satın al

    2- takipçi satın al

    3- takipçi satın al