1

How do dynos consume hours?

  • Given that I have a 1000 hour quota, if I only have a single dyno in a project, does that mean I will never go over my quota? (As the dyno hours / day exceeds 24 in that case)
  • Can I host a JSON file and have it be requested by another domain (or a localhost)? How is this affected by the 30-minute timeout? Will it take longer for the request to be handled?
  • If I plan on having a Node.JS server requesting information from a Google Sheet via the Google Sheets API, then updating a JSON file with that information, can one do that within a single dyno?
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
CAG2
  • 381
  • 2
  • 14

1 Answers1

3

The documentation says:

Every Heroku account is allocated a pool of free dyno hours. An app actively consumes free dyno hours if the app is set to use free dynos and any of the following are true:

  • It has a web dyno that is receiving traffic (i.e., not sleeping)
  • It has a worker dyno running
  • It has a one-off dyno running. For example, one started via the CLI or Scheduler.

If you only have a single dyno you shouldn't be able to go over 744 hours (24 hours / day × a maximum of 31 days in a month) a month. But if you are also using workers or one-offs (e.g. via Heroku Scheduler) you could.

When your free dyno sleeps after 30 minutes of inactivity the next request will take longer to receive a response. This is because Heroku needs to wake your dyno up.

Yes, you can host JSON file to be requested by arbitrary HTTP clients. However, you should note that Heroku's filesystem is ephemeral. Any changes you make to the filesystem (like saving a file) will be lost whenever your dyno restarts. This happens frequently (at least once per day).

A better solution would be to use a client-server database to store your data and build a JSON response from that data dynamically. Heroku Postgres is a simple option with a free starter tier, but there are other options too.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • 1
    Would it be possible to have the Dyno sleep for most of the day, then wake it at a specified time to update the info in the database? Will this use up Dyno hours? – CAG2 Sep 09 '19 at 00:25
  • 1
    While it's sleeping, no, that doesn't consume dyno hours. It sounds like you want to use Heroku Scheduler (see the link in my answer) to run an update job at some particular time. That creates a new one-off dyno to run the job. Hours are consumed while the one-off dyno is running, but once the job completes the dyno is destroyed. – ChrisGPT was on strike Sep 09 '19 at 00:36
  • So in this case, would it be possible to completely disable the 'main' Dyno and only have the one-off Dyno consume hours? – CAG2 Sep 09 '19 at 12:56
  • @CAG2, you could, but if you want to respond to HTTP requests you'll need a `web` dyno. It should probably be configured to run all the time (though if it's free it will be subject to the sleeping rules described above). – ChrisGPT was on strike Sep 09 '19 at 16:59