Search code examples
herokudyno

How does a single dyno consume hours?


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?

Solution

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