Is there any way to use autoidle in heroku for free? - heroku

I want to save my dyno by putting the heroku into idle during night times but it is paid so is there any way to use autoidle in heroku for free?

If your web application is on the Free tier then it will automatically sleep after 30 min inactivity (i.e. where there are no HTTP requests).
In the case of a worker (background process, it doesn't sleep when deployed standalone) you can use the Platform API to manage the Dyno lifecycle

Related

Worker Dyno go to sleep with the Web dyno

I'm using heroku to host my discord bot
My bot is mostly designed to be used with the discord chats, but it have a web dashboard for when in need too. I put the bot on heroku, everything seems to be working well, I know about the 30 minutes sleep time for web dyno, and it was fine, since the web dashboard is only used every so often, not 24/24 like the bot. The issue here is, when the web dyno go offline, it also brought the worker dyno down too, which is not what I wanted. Although the documents say that "Worker Dynos do not sleep, since they don't handle web requests", clearly that my worker dyno is sleeping with the web dyno. I don't want to use pinging services, since my 1000 free hours is not enough for both dynos to stay online. Is there a workaround for this? Thanks

Heroku - Can app get recycled while it is being used?

I plan to deploy a mini web app to resize photos to the heroku free tier. I read that the heroku file system is ephemeral - uploaded files get deleted when the dyno restarts. What I want to know is if I upload an image only for a short duration to change its properties and then download it, is there a chance that it will get deleted before I download it? That is, can the app get cycled when it is in use?
Regards,
Debashish
On a free tier a web dyno gets cycled on:
1) Dyno restarting - according to the documentation
Dynos are also restarted (cycled) at least once per day to help maintain the health of applications running on Heroku. Any changes to the local filesystem will be deleted. The cycling happens once every 24 hours (plus up to 216 random minutes, to prevent every dyno for an application from restarting at the same time).
Restart can happen at any time then, when occurring, also in progress web request could be terminated. After the restart is triggered, you have 30 seconds to graceful shutdown before the process gets killed
2) Dyno sleeping - according to the documentation
If an app has a free web dyno, and that dyno receives no web traffic in a 30-minute period, it will sleep
If your web request executes during the same session all the operations to upload/change/download the image, you should be guaranteed the file does not get deleted in the process. However, you can avoid these events using monitoring services such as Pingdom or New Relic that can prevent a web dyno from sleeping

How to keep only the worker alive on Heroku free tier from within the app?

I'm testing an app with a worker and a web dyno on Heroku free tier and I'd like to keep the worker alive to be able to execute background tasks while letting the web dyno idle. By default they both go idle in 30 mins even if I have things queued on the worker.
I understand there're ways to keep the web dyno alive (and with that the worker as well), and there're ways to keep the web alive while scaling down the worker. However I'd need the worker alive and the web in idle.
I tried running a recurring job on the worker which would
Restart the dyno.
Scale the dyno down and then back up.
Both approaches worked (as in they restarted and scaled the dyno correctly) but the worker dyno would still idle after 30 mins (as if it's dependent on the web dyno). Edit: yep, that's pretty much the case as explained here: https://devcenter.heroku.com/articles/free-dyno-hours#dyno-sleeping
I could do this form the outside but it seems I'd have to constantly check for the state since a new restart doesn't seem to give me 30 mins headway. I'd also have to expose the API key which I'd like to avoid.
If I've gotten you right, you're trying to stop the web dyno and leave the worker dyno alive.
You could do that by going to the Resources tab:
And then in the 'web' section:
Press the pencil, toggle it off and press 'Confirm'.
As a workaround I currently remove the web dyno and explicitly enable it when I need it. As explained here:
Worker-only Free dynos do not sleep since they do not respond to web
requests.
My workaround was to just create two apps that deploy automatically from the same repository. Then, all you would need to do is enable the worker dyno for one and the web dyno for the other.

Heroku free quota per-app or total?

Is heroku's free 750 hours separate per app, or is it a total of 750 hours shared across all your apps?
From their site:
"Each app you create has free access to 750 dyno-hours per month and a starter-tier database."
However, from another answer on StackOverflow:
"Heroku provides, for free, 1 dyno. A dyno is an instance of your application running and responding to requests. If each instance of your application can serve each request in 100ms, then you get 600 requests/minute with the free account."
Based off of what it says there and my experience it's per app. That's talking about instances of dynos not apps. "If each instance of your application can serve each request in 100ms, then you get 600 requests/minute with the free account."
Each app you create within Heroku gets 750 dyno-hours per month for free. The number of requests your app can receive depend on the configuration of the app. For example, an app running unicorn can handle more requests than an app running something else, as unicorn can run multiple workers per dyno.
I've personally run an app on Heroku with 3 unicorn workers on one dyno, 24 hours a day, all month, and always been free (because that is ~750 dyno-hours).

Will my Heroku app working on 1 web dyno stay active if I pay for 1 worker dyno?

I currently have an app deployed on Heroku which runs on two web dynos so it won't go to sleep if it remains inactive for a certain time.
Now if I scale it down to only one web dyno (free) and instead pay for one worker dyno, will Heroku always keep my app active?
It will still idle - you NEED to have more than a single web dyno
https://devcenter.heroku.com/articles/dyno-idling
You can also use the New Relic add-on to monitor your app and keep it alive. There is a tab in settings to configure availability monitoring.
You can also avoid a single web dyno from idling by using a monitoring service like pingdom.com since it's periodically sending a request to your web dyno.
Try Pingdom. Free plans include one website check. I use this service to keep my app active all the time.
Pingdom tests your websites and other infrastructure components as
often as every minute to make sure it is all up and running.
From Pingdom Homepage
Pingdom does this by "pinging" or rather requesting a resource from your website on a regular interval. This has the side effect of keeping your website "active", cache's primed, etc.. because your website is seeing regular "traffic" (the requests coming from pingdom).
Try Un-idler. You don't need to sign in and it's free.
http://unidler.herokuapp.com/
You can try http://kaffeine.herokuapp.com/ it will ping your app every 30 minutes so your app won't go to sleep.
Try CloudUp. It visits your apps periodically to keep them awake. It is free, and you can add as many apps as you want. It also activates apps on Google App Engine and Azure.

Resources