337
votes

In the Heroku free apps the dynos seem to keep idling - my app has very low traffic but it's also not really acceptable in my case that my users have to wait 20+ seconds to spin up a new dyno.

Frankly, with that kind of wait, many will leave before the first page even displays.

So, I have a problem: should I be paying $36 a month to save each user an embarrassingly long 20 seconds when my traffic is in the single-digits per day.

Is there a way around this??

5
  • 13
    As of July 1st 2015, this will not be possible anymore, according to Heroku's announcement: blog.heroku.com/archives/2015/5/7/heroku-free-dynos . They introduced however a "hobby" plan that costs only $7 / month.
    – Cristian
    Commented May 7, 2015 at 19:47
  • 2
    There are now may virtual servers available for $5/month (or less billed hourly) that provide full shell access etc. I have used DigitalOcean for over a year now but I'm sure there's others in the space to compete. IMO a better solution if Heroku is no longer free..
    – sricks
    Commented May 14, 2015 at 17:42
  • 2
    @sricks A full VPS (which you need to manage, keep updated, configure a Git server, web server, DB server, firewall, Git hooks, backups, WAL-E, etc, etc, etc) is a different thing from Heroku (a PaaS). In some cases you want the former, in others the latter, but raw dollars should be a primary metric. Time and risk should be.
    – elithrar
    Commented Jun 22, 2015 at 5:21
  • How to install the New Relic agent on RoR app? newrelic.com/ruby Commented Feb 12, 2016 at 8:12
  • 3
    As of 1 June 2016, this is possible again if you verify with a credit card. announcement. You will get 1000 free hours a month, and there are only 730 hours in a month. Assuming you only have one dyno running, you can go 24/7 for free.
    – Luke B
    Commented Dec 24, 2019 at 1:44

24 Answers 24

378
votes

You can install the free New Relic add-on. It has an availability monitor feature that will ping your site twice per minute, thus preventing the dyno from idling.

More or less the same solution as Jesse but maybe more integrated to Heroku... And with a few perks (performance monitoring is just great).

Availability monitoring

Note: to all those saying it doesn't work: the important part in my answer is "availability monitor". Just installing the addon won't help. You also need to setup the availability monitoring with the URL of your heroku app.

14
  • 7
    do we have to install gem 'newrelic_rpm' too to prevent the dyno from idling ?
    – simo
    Commented Jun 8, 2012 at 7:43
  • 4
    How much does this increase the dyno usage by?
    – Trevoke
    Commented Oct 2, 2012 at 0:00
  • 4
    I just discovered this fairly recently. It does still work excellently. Just in case, though, I make sure I do a simple DB query before displaying an 'Application Available' message. This also works great with Pagoda, and any other sleepy host. Commented Jun 18, 2013 at 21:21
  • 8
    @aubraus: your edit was rejected... Anyway: to all those saying it doesn't work: the important part in my answer is "availability monitor". Just installing the addon won't help. You also need to setup the availability monitoring with the URL of your heroku app.
    – Pierre
    Commented Aug 2, 2013 at 7:04
  • 18
    In case anyone's still looking for this, the direct link for the ping is here: synthetics.newrelic.com/accounts/[your_account_id]/monitors/new Just sub in your account ID.
    – Eric Yang
    Commented Apr 16, 2015 at 23:01
110
votes

You can also try http://kaffeine.herokuapp.com (made by me), it's made for preventing Heroku apps to go to sleep. It will ping your app every 10 minutes so your app won't go to sleep. It's completely free.

4
  • 6
    is it possible to remove your herokuapp from you service?
    – meteor
    Commented Mar 11, 2015 at 18:15
  • 2
    mine would still idle with this (sometimes it would be more than 30min before it would ping, but also heroku idling schedule is erratic too) so now giving new relic (above) a shot
    – JBW
    Commented Dec 16, 2021 at 23:10
  • Mine still idles Commented Jun 16, 2022 at 2:57
  • No provision for https. Can you fix?
    – rickb
    Commented Jun 23, 2022 at 16:06
104
votes

As an alternative to Pingdom I suggest trying Uptimerobot. It is free and offers 5 min interval site checking. It works very fine for me.

UPDATE 7th of May 2015: This will not be possible any more, as Heroku will change their free dyno to prevent keeping it alive for full 24 hours:

Another important change has to do with dyno sleeping, or ‘idling’. While non-paid apps have always slept after an activity timeout, some apps used automatic pinging services to prevent that behavior. free dynos are allowed 18 hours awake per 24 hour period, and over the next few weeks we will begin to notify users of apps that exceed that limit. With the introduction of the hobby dyno ($7 per month), we are asking to either let your app sleep after time out, or upgrade to this new option.

When is this going to be live? According to their blog post:

Applications running a single 1X dyno that don’t accumulate any other dyno charges will be migrated gradually to the new free dynos beginning on July 1.

6
  • 1
    Uptimerobot seems to be (ironically) down. You can sign up and log in, but if you try to add a new monitor, it just says "monitor already Commented Aug 16, 2013 at 23:03
  • Seems to work fairly, well... I understand heroku sleeps things on free services, but it sucks when hosting a central coordinator (which by natur can't be scaled).
    – jonasfj
    Commented Apr 1, 2014 at 22:10
  • I wasn't able to do this as Uptimerobot requires an IP address?? I can't see how to get it to work with a url, like a herokuapp url. EDIT: My bad, I was putting in the http:// and getting an error. Commented Jul 10, 2014 at 14:34
  • 1
    The big difference is 5 minute intervals means it'll be 5 minutes before you get notified if it's down. We use Pingometer (pingometer.com) which has 1 minute intervals and it's been great with Heroku.
    – okoboko
    Commented Nov 18, 2014 at 7:47
  • 13
    As of April, 2017, the 18 hour limit is gone, you can have your free dyno up 24/7, provided your account is verified. devcenter-staging.heroku.com/articles/free-dyno-hour-faq.
    – bagonyi
    Commented Apr 15, 2017 at 22:16
81
votes

In my opinion, using the 'free' tier of the service should not be powering a production or customer facing application. While the above solutions work against the Dyno idling, think thoroughly about what you're doing.

If nothing else, use a cron job to ping your site, and disable the check for known low-use periods (ie, overnight) to ensure Heroku doesn't do away with the free tier for everyone else.

5
  • 1
    Thanks for your answer. What do you mean specifically by 'think thoroughly about what you're doing'?
    – sscirrus
    Commented Jun 21, 2012 at 20:48
  • 38
    Largely for people who read the above answers for this solution. The goal of the free tier on Heroku isn't to host a production app that needs to be available for customers. The free tier idling allows Heroku to offer this level for development / testing, without a large overhead cost of constantly running servers.
    – drowe
    Commented Jun 26, 2012 at 13:58
  • 32
    It's also fine for a "production" site with low traffic and no paying customers, which you don't want to wait thirty seconds for the first page to load.
    – alxndr
    Commented Oct 3, 2013 at 0:43
  • 2
    You are correct, but there are many valid reasons for just running one dyno... Such as having a single coordinator with some state in memory...
    – jonasfj
    Commented Mar 29, 2014 at 0:20
  • 17
    You don't know very much about his app so I think your comment is fairly judgemental considering. Commented Jul 16, 2014 at 11:53
45
votes

You can use http://pingdom.com/ to check your app; if done every minute or so, heroku won't idle your app and won't need to spin-up.

5
  • 2
    So hard to decide between the two answers! In the end I went with Newrelic because I already have an account there. Thanks a lot for this great suggestion - it did actually solve my problem too. :) +1.
    – sscirrus
    Commented Mar 30, 2011 at 16:28
  • 2
    Why do it every minute? As you can see in @newe1344's answer, Heroku spins down the dyno after an hour of inactivity. So surely pining every 59minutes is more efficent? Commented Oct 28, 2013 at 17:56
  • 3
    It reports when it's down, so the minute frequency works well for both preventing sleep, and reporting downtime Commented Oct 28, 2013 at 21:46
  • I dont think its(still?) free. Commented Aug 13, 2014 at 3:45
  • @rahulserver - You're correct, Pingdom no longer has a free account. Commented Dec 5, 2014 at 13:58
45
votes

Easy answer--if you value the service then pay for it.

All these 'tricks' to get the benefits of paid service...well it's essentially like stealing cable. Questionable to even list them here. What's next, tricks on how to pirate games?

Like another poster here, I value the free service for development and testing and I will be greatly annoyed at all you ethics-impaired types if Heroku does away with it because there are too many freeloaders. I just don't think he was direct enough in his criticism.

11
  • 23
    It's a paid service, with certain terms. Why not optimize your use of the service within those terms to get the most out of it?
    – pkinsky
    Commented Feb 4, 2014 at 18:49
  • 8
    Well I believe I already indicated the reason, but to spell it out a bit further--the intended use of the free hosting is clear. And the advantage of 'always on' is a perk of paying even just the pittance for a second worker. All the exploits here involve uselessly consuming resources to get out of paying for a service. It is shameful behavior. Why should I care? Because if they get fed up, their recourse will be to do away with the free service which, used as intended, is of great value to me.
    – elc
    Commented Feb 18, 2014 at 18:48
  • 2
    Okay just to clarify for you drive-by downvoters, he doesn't only ask "Is there a way around it?" he also asks "Should I be paying..." This is what I am answering. It is the more fundamental question. Sure there are tons of trivially easy ways to bypass. They are ethically wrong, so it is at best a waste of time to detail them here, and arguably considerably worse as it constitutes enabling and encouraging poor behavior.
    – elc
    Commented Apr 3, 2014 at 22:29
  • 5
    That's a bit overreaching. We deploy to heroku while testing. When our customers go to the site when it's been idle they assume there's something wrong with the app we developed to connect to the service. Keeping the site alive for the sake of responsiveness to demo an app that may never see light of day is hardly unethical. Sounds like a personal conviction, not ethics. If it doesn't violate the rules or the law, your ethical presumption is the only thing that is wrong. Freemium is a legitimate business model. It's okay to "take advantage" of the free part of that. It's expected.
    – Matt Long
    Commented Jul 3, 2014 at 0:01
  • 1
    So your justification is "everybody else is doing it" That's not really a new argument. Or a convincing one. edit Sorry you do make a point that is valid to some people. That what is being done is not explicitly prohibited so therefore it is not wrong. I know there are people who believe 'what is not expressly prohibited is permitted' and take it further to say it is not only permitted but is 'not wrong'. That whole attitude is what I would label overreaching in a very self serving way. But it does come down to a fundemental philosophical difference.
    – elc
    Commented Jul 14, 2014 at 23:15
36
votes

Tested and working on my own Heroku app using Node.js 0.10.x on 6/28/2013

var http = require('http'); //importing http

function startKeepAlive() {
    setInterval(function() {
        var options = {
            host: 'your_app_name.herokuapp.com',
            port: 80,
            path: '/'
        };
        http.get(options, function(res) {
            res.on('data', function(chunk) {
                try {
                    // optional logging... disable after it's working
                    console.log("HEROKU RESPONSE: " + chunk);
                } catch (err) {
                    console.log(err.message);
                }
            });
        }).on('error', function(err) {
            console.log("Error: " + err.message);
        });
    }, 20 * 60 * 1000); // load every 20 minutes
}

startKeepAlive();
2
  • 3
    In my view the best solution, since it does not rely on any third party service. Thanks :) Commented Dec 9, 2014 at 12:50
  • It seems that it does not avoid going to sleep. But it works to automatically go up again. I dont know if this behaviour is because of changes, actually you solution comes from almost two years ago.
    – jgato
    Commented Feb 12, 2015 at 10:12
30
votes

I use the Heroku Scheduler addon provided by Heroku for free. Once added it is simple as creating a job with 'curl http://yourapp.herokuapp.com' and a 10 min interval.

2
  • I think this is the simplest solution so far, thank you @Jordan Commented Jun 14, 2021 at 1:28
  • 2
    the only downside of this is, they ask for credit card info before offering this addon.
    – prgmrDev
    Commented Jan 4, 2022 at 10:41
20
votes

Add your app's URL to http://kaffeine.herokuapp.com/.

From the site:

Kaffeine pings your Heroku app every 30 minutes so it will never go to sleep*

Kaffeine pings your Heroku app every 30 mins so it will never go to sleep

1
  • No provision for https.
    – rickb
    Commented Jun 23, 2022 at 16:05
11
votes

It says in Heroku documentation that having more than 1 web dyno will never idle out. Possibly a cheaper solution than $0.09/hour like Pierre suggests.

enter image description here

Documentation

1
  • 6
    The Heroku add-on has a free standard version.
    – sscirrus
    Commented Feb 2, 2013 at 19:06
10
votes

I have written down the steps:

➜ Add gem 'newrelic_rpm' to your Gemfile under staging & production
➜ bundle install
➜ Login to heroku control panel and add newrelic addon
➜ Once added, setup automatic pinging to your website so that it does not idle
➜ Browse to Menu > Availability Monitoring (under Settings) → Click “Turn on Availability Monitoring”
➜ Enter the url to ping (eg: http://spokenvote.org)
➜ Select 1 minute for the interval

3
  • 3
    Thanks Pratik. FYI if you ping your app every minute you'll be using up bandwidth without any benefit to idling. Unless you have another reason it's safe to scale that back a touch.
    – sscirrus
    Commented May 3, 2013 at 19:39
  • 3
    Heroku will only put your dyno to sleep after 1 hour of inactivity, so you can scale the interval back to 1 hour (or maybe 50 minutes to be on the safe side). Commented Sep 1, 2013 at 5:48
  • Question: Do you happen to know where to change that ping interval? It seems to be not an available option in the dashboard settings.
    – mishap_n
    Commented Jul 17, 2014 at 5:21
10
votes

A cron job will do. See https://cron-job.org. It's free and reliable.

6
votes

Most of the answers here are outdated or currently not working. The current free tier for personal accounts are gives a base of 550 free dyno hours each month.

And a verified free account gives you 1000 hours of free dyno. I wrote an article on how I made my free app stay awake.

https://link.medium.com/uDHrk5HAD0

Hope it helps anyone who is in need of a solution in 2019

5
votes

I found another free site that will constantly ping your site called Unidler

http://unidler.herokuapp.com/

Same as pingdom, but doesnt need to log in.

1
  • How to remove after adding?
    – Lekr0
    Commented Mar 16, 2020 at 4:57
4
votes

If you have access to a unix server that's always up, you can set a cron job to GET your website. Under the new terms of the free plan, you'll probably want to disable the GETs in the night hours, using a line in your crontab like this:

*/20 8-22 * * * /usr/bin/curl domain.com &> /dev/null

This instructs curl to GET domain.com every 20 minutes between the hours of 8 and 22.

Be aware that

  1. Not everyone who wants to see your website lives in your timezone and
  2. Your site may receive other requests in the middle of the night, waking up your dyno and causing another hour of usage time for each request. Even if no one else knows your domain, there are bots and crawlers that are active all the time. Therefore, it's advisable to set the process defined in your crontab to be active for only 14 to 16 hours to provide a buffer against these wake-ups

Also, make sure your system time is set up properly so that the down-time window happens when you expect it to.

4
votes

This is my solution.

Use Google Apps Script, and set time trigger.

// main.js
function ping() {
  UrlFetchApp.fetch("https://<Your app>.herokuapp.com/ping_from_GAS");
}

It is very easy!

1
  • This is such a good solution! Thanks for the suggestion! Commented Feb 12, 2022 at 0:12
3
votes

this work for me in a spring application making one http request every 2 minute to the root url path `

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.client.RestTemplate;

public class HerokuNotIdle {

private static final Logger LOG = LoggerFactory.getLogger(HerokuNotIdle.class);

@Scheduled(fixedDelay=120000)
public void herokuNotIdle(){
    LOG.debug("Heroku not idle execution");
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getForObject("http://yourapp.herokuapp.com/", Object.class);
}
}

Remember config your context to enable scheduler and create the bean for your scheduler

@EnableScheduling
public class AppConfig {

@Bean
public HerokuNotIdle herokuNotIdle(){
    return new HerokuNotIdle();
}
}
3
votes

Note that the new dyno types (currently in beta, incoming in June 2015) will forbid to keep a free dyno awoken 24/7, as it would have to sleep at least 6 hours per day.

So try to remove any solution you found in this thread before this comes out (or pay for the service you actually use).

2
votes

Guy, here is a heroku app you can run to keep multiple heroku apps alive. Just add the urls you want to ping in the config.json.

https://github.com/jcarras/rise-and-shine

2
votes

I have an app that only needs to run from monday to friday around lunchtime. I just added the following script to the crontab at work:

#!/bin/sh
# script to unidle heroku installation for the use with cronjob
# usage in crontab:
# */5 11-15 * * 1-5 /usr/local/bin/uptimer.sh http://www.example.com
# The command /usr/local/bin/uptimer.sh http://www.example.com will execute every 5th minute of 11am through 3pm Mondays through Fridays in every month.
# resources: http://www.cronchecker.net
echo url to unidle: $1
echo [UPTIMER]: waking up at:
date
curl $1
echo [UPTIMER]: awake at:
date

So for any app just drop another line in your crontab like:

*/5 11-15 * * 1-5 /usr/local/bin/uptimer.sh http://www.example.com
2
votes

I think the easiest fix to this is to self ping your own server every 30 mins. Here's the code I use in my node.js project to prevent sleeping.

const request = require('request');
const ping = () => request('https://<my-app-name>.herokuapp.com/', (error, response, body) => {
    console.log('error:', error); // Print the error if one occurred
    console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
    console.log('body:', body); // Print body of response received
});
setInterval(ping, 20*60*1000); // I have set to 20 mins interval
1
vote

One more working solution: wokeDyno Here is a blog post how it works: It's integrated in the app very easy:

/* Example: as used with an Express app */

const express = require("express")
const wakeDyno = require("woke-dyno");

// create an Express app
const app = express();

// start the server, then call wokeDyno(url).start()
app.listen(PORT, () => {
    wakeDyno(DYNO_URL).start(); // DYNO_URL should be the url of your Heroku app
});
0
votes

Freshping is another free resource that can keep your free Heroku app alive 24/7.

0
votes

if you're using nodejs with express, you could add an endpoint that will call itself every 10 minutes.

router:

app.get("/keep-alive",require("path/to/keepAlive.js").keepAlive);

keepAlive.js

let interval;

function keepAlive(req, res) {
   if(interval) return res.end();
   
   interval = setInterval(() => {
      fetch("http://your-heroku-subdomain/keep-alive")
         .catch(err => {/*handle error here*/});
      }
   ,60_000);


   return res.end();
}

module.exports = { keepAlive }

Not the answer you're looking for? Browse other questions tagged or ask your own question.