npm and node_index.js high CPU load

Is there any way to throttle down CPU load for npm and node_index.js?
After Node-red instalation CPU load for those two services is jumping to 100% every 2 seconds. :thinking:

Hi,

you could use tools like cpulimit

https://linoxide.com/linux-how-to/limit-cpu-usage-processes-linux/

Great idea!
…but how low can we go with that, not to effect node-red too much (I use node-red just for two flows, scheduled for 2 seconds time frame per day)?

Are those two services needed just for node-red or also for some other software from dietpi list?

honestly I don’t know. I never used such a tool and usually there is a need for such CPU load. Otherwise the application would not behave like this? I guess you would need to play with it to find fitting values.

ok, I’ll try&report here.
Tnx!

test so far…
root@DietPi:/home/tibo# cpulimit -e node -l 40
Process 31076 detected
Process 31076 dead!
Warning: no target process found. Waiting for it…
Process 31107 detected
Process 31107 dead!
Warning: no target process found. Waiting for it…
Process 31150 detected
Process 31150 dead!
Warning: no target process found. Waiting for it…
Process 31181 detected
Process 31181 dead!
Warning: no target process found. Waiting for it…
Process 31224 detected
Process 31224 dead!
Warning: no target process found. Waiting for it…


it looks like node process changes PID all the time, so cpulimit cannot limit the process only by ID :frowning:

that could mean node is crashing all the the time and restarting? Otherwise I could not imagine why it is changing process id again and again

you are right.
that explains CPU load jumping.
but what causes that…
strange…
if dietpi-services stop node-red is executed, node and npm does not stop at all…

you could have a look to journalctl -u node-red

nothing strange there:

Jan 25 22:52:29 DietPi node-red[16635]: 25 Jan 22:52:29 - [info] Stopped flows
Jan 25 22:52:29 DietPi systemd[1]: node-red.service: Succeeded.
Jan 25 22:52:29 DietPi systemd[1]: Stopped Node-RED (DietPi).

npm and node_index.js still high CPU load

that’s all? looks like it is not starting correctly. can you do a reboot and check again

no, i did’t paste everything
Jan 25 23:02:53 DietPi systemd[1]: Started Node-RED (DietPi).
Jan 25 23:03:05 DietPi node-red[1266]: 25 Jan 23:03:05 - [info]
Jan 25 23:03:05 DietPi node-red[1266]: Welcome to Node-RED
Jan 25 23:03:05 DietPi node-red[1266]: ===================
Jan 25 23:03:05 DietPi node-red[1266]: 25 Jan 23:03:05 - [info] Node-RED version: v1.2.7
Jan 25 23:03:05 DietPi node-red[1266]: 25 Jan 23:03:05 - [info] Node.js version: v15.6.0
Jan 25 23:03:05 DietPi node-red[1266]: 25 Jan 23:03:05 - [info] Linux 5.4.83-v7+ arm LE
Jan 25 23:03:10 DietPi node-red[1266]: 25 Jan 23:03:10 - [info] Loading palette nodes
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [info] Settings file : /mnt/dietpi_userdata/node-red/settings.js
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [info] Context store : ‘default’ [module=memory]
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [info] User directory : /mnt/dietpi_userdata/node-red
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [warn] Projects disabled : editorTheme.projects.enabled=false
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [info] Flows file : /mnt/dietpi_userdata/node-red/flows_DietPi.json
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [info] Server now running at http://127.0.0.1:1880/
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [warn]
Jan 25 23:03:24 DietPi node-red[1266]: ---------------------------------------------------------------------
Jan 25 23:03:24 DietPi node-red[1266]: Your flow credentials file is encrypted using a system-generated key.
Jan 25 23:03:24 DietPi node-red[1266]: If the system-generated key is lost for any reason, your credentials
Jan 25 23:03:24 DietPi node-red[1266]: file will not be recoverable, you will have to delete it and re-enter
Jan 25 23:03:24 DietPi node-red[1266]: your credentials.
Jan 25 23:03:24 DietPi node-red[1266]: You should set your own key using the ‘credentialSecret’ option in
Jan 25 23:03:24 DietPi node-red[1266]: your settings file. Node-RED will then re-encrypt your credentials
Jan 25 23:03:24 DietPi node-red[1266]: file using your chosen key the next time you deploy a change.
Jan 25 23:03:24 DietPi node-red[1266]: ---------------------------------------------------------------------
Jan 25 23:03:24 DietPi node-red[1266]: 25 Jan 23:03:24 - [info] Starting flows


everythimg seems fine. node-red works perfectly.

should I ignore mentioned issue or do you think that it needs to be investigated further?


after stop node-red:

Jan 25 23:09:24 DietPi node-red[1266]: 25 Jan 23:09:24 - [info] Stopped flows
Jan 25 23:09:24 DietPi systemd[1]: node-red.service: Succeeded.
Jan 25 23:09:24 DietPi systemd[1]: Stopped Node-RED (DietPi).

and starting it again?

temporary fix:

with cron job that keeps those two processes alive just for needed 1 minute per day should be ok? :smiley:

this I don’t understood. What should be the aim?

no.

node-red does not keeps restarting

so it is running fine now? No CPU spikes anymore?

I need node-red only for to few flows, all are scheduled for one second before and one second after midnight.
I can keep node-red alive only for those two seconds (or let’s say 1 minute). For RPI’s health :wink:

node-red isn’t restarting, but node and npm processes are CPU spiking

well you could create a script stating node, do a sleep 120 and stop node again. This than to be scheduled on cron