319
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??

23
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
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
@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
How to install the New Relic agent on RoR app? newrelic.com/rubyJames Brown
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 Borowy

23 Answers

366
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.

94
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.

83
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.

80
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.

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.

43
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.

34
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();
27
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.

15
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

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

9
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

6
votes

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

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.

5
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

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).

3
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.

3
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!

2
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();
}
}
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
1
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
votes

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.