Heroku Deployment and traffic - node.js

Since only one free dyno is available. How many users can simultaneously run my application?
And how does it calculate how many free dyno hours have been used

As Dominic mentions in the comments, this will depend heavily on how your application is architected -- what web server it's using, how quick responses can be returned, etc.
From the "Free dyno hours" perspective, the clock is ticking whenever the dyno is up and running. After 30 minutes of no activity, the dyno will idle and the clock will stop ticking. You can read more about this here: Free Dyno Hours

Related

Number of free dynos running

So, after my research on stackoverflow and other portals, I have not found any answer to the below question.
I am using a free Heroku account without any kind of payments. If I run, say 2, applications on the free account, does it mean that I am using 2 dynos. Because I know that two dynos will consume double the dyno hours(If both the applications never sleep. I am aware of these basics of Heroku), and so this is a concern for me.

Is it possible to have workers running "virtually" 24h/7 in Heroku?

I have real time data incoming and I need to process it 24h/7, but:
a) Heroku will restart Dynos once a day.
b) Heroku will restart Dynos when code is updated.
Point a, can be more or less handled by having multiple dynos, if one restarts, the other is still there.
But for point b, I don't see how I can handle it. If all dynos restart for an update, I'll lose data until they are up again.
Is there any solution?
Yes, you can enable preboot on your dynos.
Preboot changes the standard dyno start behavior for web dynos. Instead of stopping the existing set of web dynos before starting the new ones, preboot ensures that the new web dynos are started (and receive traffic) before the existing ones are terminated. This can contribute to zero downtime deployments.
heroku features:enable preboot -a <myapp>
Do read the entire docs - there are some important considerations / caveats to be mindful of, like the fact that deployments will now take several minutes to switch to the newer set of dynos.

Heroku how many apps on a dyno

I'm running my blog on an Heroku dyno, and too many times my users have to wait almost half a minute for my blog to respond. There are ways to prevent Heroku from idling: Easy way to prevent Heroku idling? Most obvious is to ping the server every minute or so.
But it seems those methods are against Heroku's TOS, if I check the pricing page: https://www.heroku.com/pricing (see MUST SLEEP 6 HOURS IN A 24 HOUR PERIOD). And because Pingdom does costs me some money as well, I'm thinking of paying $7 dollars a month for the Hobby package. But how many apps can you run with that package? Cause I always run one app per dyno, but if I have to pay $7 per app... That seems too much.
Anyone who knows there is a way to run multiple apps on a dyno? Or is hiring a server at DigitalOcean with NodeJS a better choice, for example?
The free and hobby dyno types only support a maximum of one dyno running per process type. Additionally, applications using a free dyno type are limited to a maximum of two concurrent running dynos.
By default, a process type can’t be scaled to more than 100 dynos for standard-1X or standard-2X sized dynos. A process type can’t be scaled to more than 10 dynos for performance dynos.

Calculating large data in Node on Heroku

I have a service that I run daily in the background with a database of about 140mb in size. The calculations I run require me to load all 140mb into Node at once, and after a minute or so quickly reach the process limit of 512mb and Heroku restarts the process.
For the mean time, a quick solution is to increase the server to 2X so I get 1 GB RAM, but within a month or so the database will outgrow that as well.
As far as Heroku goes, is my option basically to upgrade Dyno options? Since these are calculations I do once per day, I would rather run them locally on my machine and upload the results than to pay $250-500/month for the Performance Dynos.
I know I could also just upgrade to the Performance Dynos to run these services and then downgrade once finished, but I'm looking for something I can automate and not have to deal with each day.
Thanks for reading.
Heroku Scheduler seems to fit your use case exactly. You can schedule your task to run daily on a One-Off Dyno of any size, and since Heroku pricing is "prorated to the second" you will only pay for the time that your task is running on that Dyno.
I haven't actually used this, but I was about to recommend a similar solution on AWS when I searched and found this feature of Heroku.

Does heroku restart NodeJS server if application crashes

We are running NodeJS server on Heroku. we want to know whether heroku will restart the application if application crashes. Also will there any different behavior between free version and paid version?
It will. For several times, and then "cool off" for ten minutes and try again. From the docs:
Heroku’s dyno restart policy is to try to restart crashed dynos by spawning new dynos once every ten minutes. This means that if you push bad code that prevents your app from booting, your app dynos will be started once, then restarted, then get a cool-off of ten minutes. In the normal case of a long-running web or worker process getting an occasional crash, the dyno will be restarted instantly without any intervention on your part. If your dyno crashes twice in a row, it will stay down for ten minutes before the system retries.
The docs: https://devcenter.heroku.com/articles/dynos#automatic-dyno-restarts
EDIT Regarding free dynos: the restart behavior is the same. However, there is something called "Dyno Idling" which happens only in free dynos. Basically it means that if your dyno does not receive any request for 1 hour it will "go to sleep", and the next request will "wake it up", which will cause that next request to be slightly delayed. This happens only when you have 1 free web dyno for your app.
To circumvent that, either have 2 dynos (and then none of them will idle, but you will be paying for one), or have "something" poll your web dyno every (say) 30 minutes. Like pingdom, say.
The docs: https://devcenter.heroku.com/articles/dynos#automatic-dyno-restarts
Fast-forward to 2022, Go to your app on the Heroku portal
Click on "More" dropdown
Select "Restart all dynos"

Resources