Node.js, Sails.js servers time out - node.js

Environment: Windows Server 2008
I have a Node.js and a Sails.js apps. For example, my Node.js app does something like this:
http.createServer(function(req,res){...}).listen(8000);
Both are really simple apps, but I need them available at all times. I had problems creating a Windows Service, so i created a task for each app in the Task Scheduler.
They seem to be working fine except for when the apps haven't been used for over an hour or so (not sure on the exact timing). After some time when I go to localhost:8000, my Node.js app (same with my Sails.js app) responds only after about 10-20 seconds, and in less than a second in the following requests.
I am thinking about writing another task :) - a warm-up script that will send periodic requests to keep the apps running. But there's gotta be a better way! Is there a server timeout setting in Node.js/Sails.js that can be disabled/modified?

Related

Node app running on cPanel hosting shuts down after 30 minutes idle

I have a REST api node app.
Once its running on localhost, it runs until I stop the dev debugging, no errors.
I moved it over to my cPanel hosting, installed a node app.
It starts up the same as localhost.
But after 30 minutes being idle, it shuts down.
The next request after this, restarts the app.
There are no crash or errors in the log, just the restarting messages.
I know this is default behaviour for free hosting, like Heroku but I'm paying for this hosting package.
Does anyone know...
Is this default behaviour for cPanel hosted node apps, or is my app causing this (using too much memory or cpu for example?
Is there any settings that can be edited to change this?
According to the docs, cPanel uses something called Phusion Passenger to run Node.js. In turn, Passenger docs show a default "idle time" of 5 minutes and a default of passenger_min_instances = 1. No idea if cPanel changes the defaults, or if the hosting provider did. I would recommend contacting the hosting provider about the issue in any case, and asking about these options specifically - they may be able to help or tune the service for you.
The startup time for a node app depends on what it's doing. A rest-api could be in the milliseconds, whereas a small Ai app loading a corpus or training a dataset (which mine was) could end up being 30 seconds plus. However the quantity of users did not warrant a dedicated server, so the work-around was to call the endpoint using a CRON, keeping the app alive.
Not perfect, but this type of thing may be useful if you are using aws lambda, which calls a 3rd party service, and which charges based on time taken. Every millisecond counts.

Angular 8 Universal (Server Side Rendering) app is crashing

I have deployed an Angular 8 universal app in a server droplet of Digital Ocean. It is running in production. The server config is 4GB memory and 2 vCPU. The app is run via nodejs in the server. It's been running fine for over a month until recently it suddenly started crashing in no definite time. Since it's running in my client's computer browser, I don't know any way to monitor the error in their console. I also run this app with NOHUP command which dumps all the server side node js logs in a nohup.out file. But nohup.out file shows nothing about the crash.
Things that happened around the crash event started to happen.
1. I have pushed an update which is totally unrelated to the bootstrapping of the app. As per my understanding the Angular universal only renders the initial view and sends it to client browser. After that it's the browser that takes care of rest of the jobs.
The app uses websocket to maintain a bidirectional connectivity with the backend app written in Java. Also I don't think WS is the reason, because after implementing the WS feature, it ran just fine for over a week.
Thirdly i noticed that there are some image links(of the website) that are loaded from a CDN/Edge server and for last couple of days some static files located in the CDN server are taking too long to load/download. The response time to load those files spike up to 25-26 seconds sometimes. Since these static files are loaded during startup, can the delay of loading the static files cause any type of timeout event when Node JS renders the page in the startup?
As you can understand I have no clue how to debug this thing. Is there anyway who faced similar crashing issue with Angular Universal and help me point to the right direction? Thanks

How to fine-tune NodeJS server deployed to Azure WebApp for massive load

I deployed node js server to Azure WebApp, and it worked fine. But, I see that sometime the response time is very slow. Also, I see that somewhere above 500 request/second the server start to fail handling request, and I see it use only 15% CPU. Now, I checked and the server return 500 error because the pipe is busy (by the win32 error code). That's why I was wondering if there is something I can change in the IISNode config to improve the server request capacity.
I already enabled the AlwaysOn feature, and also I add a check in Pingdom to keep the site alive. Also, I already changed nodeProcessCountPerApplication to 0 so it use all the available process.
Thank you,
Omer
One thing you can do is enable Always On. Without it, when your site hasn't been visited for 20 minutes the site gets taken down. Then the next time someone makes a request to your site Azure Web Apps warms up (re-sets up) your site but this process takes a few seconds.
Note that Always On is only available for sites in Basic, Standard, or Premium SKUs
Also, check out this page for tips on debugging Node.js apps in Azure Web Apps: https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-debug/

Long-running intervals in Azure with Node.js

I'm running a Node.js app in an Azure website and I'm trying to get a timer to go off every 30 seconds indefinitely. I've tried using both setInterval and node-cron but both of these stop working after about half an hour. There are no errors in the logs, and the site stays up, but the timer stops firing. I can start or recreate the timer again but it just stops working after another half an hour.
I am on the free trial period, am I running into some sort of account restriction here? Or is there some other way I should be doing this or some way to work out what is making the timer stop?
When hosting Node.js on a website (or in fact using the node.js powershell support for Cloud Services) your node process is hosted by IISNode.
IISNode will manage the lifecycle of the node process. I'm guessing it's intentionally shutting you down after 30 minutes.
You need to run node yourself in Azure if you want a process that's going to stay up. There are two options:
Use the Virtual Machines (currently in preview), and manually copy node.exe, and your javascript onto a virtual machine, and start your app manually (or as a scheduled task or something). You can use either Windows or Linux.
Use Cloud Services, and create a Worker Role which starts node as a startup task. This gives you the ability to scale as well.

Proper implementation of node.js worker process on Heroku Cedar

I have a process that needs to be run periodically - on a Rails app, it would be a worker process. Is there an equivalent for node.js on Heroku?
I'm currently using node-cron to run the periodic process on the same server as my web application. Issues here are:
With only 1 web process, it won't run when the server idles
It will block incoming connections while running
When scaling, the process doesn't need to be run on multiple servers
If it is the case that Heroku simply does not yet handle this, I'm interested in seeing other Node PAAS providers solution here.
you must have missed the new Heroku Cedar app that does all of what you want - read more at
http://devcenter.heroku.com/articles/node-js

Resources