Saturday, February 7, 2015

How to prevent your Heroku dyno from going to sleep

If you are using a free Heroku web dyno, you might have already noticed that sometimes it takes too long to load your website. The reason is that single 1X or 2X web dynos go to sleep after one hour of inactivity. This causes a few second delay for the first request. However, subsequent requests should perform normally.

In order to prevent this, you can do the following:

1) Install Heroku Scheduler free add-on (heroku addons:add scheduler:standard)
2) From your Heroku Scheduler dashboard, add a new job with these details:
- Task: $ curl -I http://YOURAPPNAME.herokuapp.com
- Dyno size: 1X
- Frequency: Every 10 minutes
3) Save the changes
That's it! Heroku Scheduler will send a "keep awake" signal to your app every 10 minutes, so that it won't fall asleep.

Important: Heroku Scheduler runs one-off dynos that will count towards your dyno-hours for the month and you might be charged for extra usage.

No comments:

Post a Comment