0

After some Chrome debugging I noticed it takes nearly 6 seconds to wake up which is not acceptable.

There are about 5 - 10 ways to keep it awake depending upon how you are counting: A google search pulls up a myriad of sites and ways to do this.

Some methods suggest regular pinging while others suggest regular GET requests.

I went with regular GET requests as it is just a small file to add to my server:

const http = require("http");
let INTERVAL = 300000; // 5 minute, keep a let for debugging
INTERVAL = 600000; // 10 minutes 
const SITE = "http://www.your-site.ai";

let count = 0;

setInterval( () => {
  count++;
  wakeSite();
}, INTERVAL);

function wakeSite() {
  const output = http.get(SITE);
  console.log('DEBUG: ' + count);
}
function interface () {}
wakeSite();
module.exports = interface;

What should I set INTERVAL to and where is this documented in the Heroku documentation?

According to this Heroku article from 7 years ago, apps go to sleep after 1 hour.

Is this still valid and what wakes an app up? A simple ping request or does it need to be a full GET. Does Heroku support regular "josteling" of the app?

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

1

If an app has a free web dyno, and that dyno receives no web traffic in a 30-minute period, it will sleep.

https://devcenter.heroku.com/articles/free-dyno-hours

Connections to one-off dynos will be closed after one hour of inactivity (in both input and output). When the connection is closed, the dyno will be sent SIGHUP. This idle timeout helps prevent unintended charges from leaving interactive console sessions open and unused.

https://devcenter.heroku.com/articles/limits#dynos

So any web traffic will wake it up

There is already enough answer about how to prevent it, like this one

Vitaly Migunov
  • 4,297
  • 2
  • 19
  • 23
  • 1
    A get request seems like overkill. Could I just have a setTimeout in my Node server code that updates a single variable without any network activity at all? Or did I not understand your answer when you said "any activity"? –  Jun 30 '19 at 04:38
  • 1
    I am doing internal GET requests and it is working fine. I don't think the web traffic even needs to be "external" –  Jun 30 '19 at 22:07
-1

After some Chrome debugging I noticed it takes nearly 6 seconds to wake up which is not acceptable.

If this is "not acceptable" you should pay for a hobby-tier (or higher) dyno. They never sleep, and carry additional benefits like ACM.

If you insist on staying on the free tier please bear in mind that there is a limit to the number of free dyno hours you can use:

Accounts are given a base of 550 free dyno hours each month. In addition to these base hours, accounts which verify with a credit card will receive an additional 450 hours added to the monthly free dyno quota. This means you can receive a total of 1000 free dyno hours per month, if you verify your account with a credit card.

450 hours is about 23 days (clearly not enough to run for a full month), and these hours are shared across all free dynos in your account. Even with a verified account you only get about 41 hours a month—not enough to run two dynos constantly.

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257