AWS EC2 100% CPU utilization - node.js

I try to host my product to AWS EC2 service and I faced with a problem.
My service is a Node.js app. It do some CPU intensive initialization after start. It stucks after about a 30 sec of work any time I started it. I added detailed logs of the app execution and according them looks like app is totally hung on. However CPU usage is 100%.
I've tried to run the app on many different types of instances. The last try is running on c5n.xlarge instance. OS is Ubuntu 18.04. In all cases my app is stuck. Meanwhile, my app perfectly works on Heroku Free and Hobby dynos (https://www.heroku.com/pricing) and on my local PC with Core i5-3450 CPU.
What the problem might be?

The problem is not linked to AWS EC2. The reason was usage an unstable version of module under the concrete Node.js version.

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.

Nodejs application overloading CPU

I am facing a CPU overload issue due to a nodejs application that I am running in a remote Ubuntu 16.04 LTS virtual machine. I am using PM2 to schedule my nodejs application as a service.
Initially when the nodejs application is launched, the CPU load remain quite low; about 30% at most. Then slowly I find the CPU load going up till it gets to 100%. This nodejs application is polling a stock website for new information on a stock and then does some calculations and then repeats after 5 minutes. I dont see how its causing this overload on the CPU.
I notice that my 1 nodejs application shows up as 6 different processes in HTOP command. Not sure if this normal or how to fix this. Any help would be highly appreciated.
Thanks
Regards,
Adeel
Thanks, Gerard. Your reply helped solve the problem. Turns out guardian.js was not exiting and just opening up new processes till it overloaded the system.

Error-Openstack Installation Cinder API did not Start

I tried installing devstack OpenStack-liberty on Ubuntu 14.04 Using VM Virtualbox. I want to integrate nova,swift,cinder along with OpenStack. I have enabled services for cinder in localrc file. After trying so many times i.e stacking(run ./stack.sh) and unstacking ,I ended up getting the same error:
'c-api did not start'
The problem was due to resources. I was using 4GB RAM which was not sufficient. Few APIs consume more RAM while starting. Openstack Installation console waits for a while and expects APIs to start, which wasn't happening in my case due to less dedicated RAM since I was using 4GB of RAM in which only 2.5GB RAM was given to my VM.
After struggling few days I got to know the issue and upgraded my system's RAM to 8GB, and it worked!
So I suggest people who want to work with Openstack-Swift and Openstack-Neutron should dedicate minimum of 5.5GB to VM!

AWS micro instance has 95% + and Nodejs app is not accessible in the browser

The CPU usage is consistently over 95% for the NodeJs app. Even though the nodejs app is running, when I try to access it in the browser, its not accessible at all.
I'm running on a Micro instance for testing purposes.
Why is this happening and what might be a solution for this?
t1.micro and all t2 instances use a burstable CPU model. While idle, you build up credits. When active you use credits. Once you hit 0, your instance is throttled.
You can confirm this by looking at CPU credit usage and balance in Cloudwatch.
To fix, use a larger instance, maybe t2.small.

Profiling high CPU usage (with Nodetime) on my Node.js app running on Amazon ec2

I have been trying to do some load testing (using BlazeMeter) on my node.js app running on an amazon ec2. I started testing with 500 users hitting my endpoint on the t2.Micro but this soon collapsed (maxing both memory and CPU). I tried similar test on the t2.Small, t2.Medium and c3.large, with all of these tests, the memory was fine but I would end up maxing CPU and eventually response times would get above 60 seconds and I would get a 504 Gateway timeout from nginx.
I have tried profiling my app with Nodetime but nothing looks very strange:
It doesn't seem like any of the listed tasks is using much CPU but top tells me that the CPU (or CPUS running on c3.large) are totally maxed, and this leaves me a bit confused.
Am i reading this wrong?
EDIT:
Here is a screenshot of top showing node maxxing the CPU:
Try profiling for more time or on time when the CPU goes high.
Probably your profile time did not catch the peak CPU usage

Resources