High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

For heating/cooling related questions in Domoticz

Moderator: leecollings

Post Reply
User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by Domoberry »

Hi Forum,
There are some posts related to this topic, but none was conclusive for me. I'm hoping for some guidance to resolve this high CPU load issue.
Normally, my RPI would run below ~2% CPU, but with the NefitEasyHttpServer load increases to 25-30% on average which increases the temperature of the RPI. I used to run Domoticz+Nefit on the same RPI with Stretch and the pre-2020 Domoticz version.
I'm using node v10.21.0, npm v6.14.4, for the nefiteasyhttpserver, I'm not sure about the version (how to check? With "sudo pm2 show nefiteasyhttpserver", the version is indicated as "N/A")
I'm assuming NefitEasyhttpServer is triggering the extra load, since if I disable it using ("sudo pm2 stop nefiteasyhttpserver") I note the CPU load (and the temperature) drop sharply, which is reversed when I enable it again ("sudo pm2 start nefiteasyhttpserver").
200616 CPU increase for nefiteasyhttpserver.JPG
200616 CPU increase for nefiteasyhttpserver.JPG (35.27 KiB) Viewed 1275 times
Here you can see the effect of starting and stopping the nefiteasyhttpserver; on around 19:30, off bot after 20:00, etc.
Probably, some additional information is required, which I will gladly provide, realizing that I'm quite far from the level many of the experts on this forum!

(I have recently upgraded my RPI from Stretch to Buster following the steps from https://pimylifeup.com/upgrade-raspbian ... an-buster/ in order to keep the current setup and downgraded nodejs from 12.18.10 to v10.21.0 as I seemed to have some problems with installing the nefiteasyhttpserver). At the same moment I also upgraded to Domoticz 2020.2)
User avatar
FireWizard
Posts: 1893
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by FireWizard »

User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by Domoberry »

Thanks for the tips Firewizard!

I had seen https://github.com/robertklep/nefit-eas ... /issues/17 and consequently was not sure which version I had installed. So here is probably a noob questions: how to ensure I get the latest (or a specific version) and can I replace the existing version simply by executing something like "sudo npm i nefit-easy-http-server –g" ? Hints appreciated!

I had *not* seen https://github.com/robertklep/nefit-easy-core/issues/19. This is definitively one I need to 'digest' it since it strongly resembles the problem I'm seeing. Also, my guess is not so much an issue with the nefiteasyhttpserver, but rather something with the way I'm using it (or 'misusing' if you want).
Initial reaction: using ps aux, I see some double entries. Like I said, need to digest this.

Cheers,
User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by Domoberry »

With https://github.com/robertklep/nefit-ea ... /issues/19 as 'mental guidance', as well as a colleague of mine with a (much) better understanding, I have made a few steps forward.
- The version of Nefit Easy Server is 5.0.3, and can be found by issuing:

Code: Select all

easy-server -v
- The most likely root cause of the high CPU load and corresponding high CPU temperature is the fact that at some point in time I had two instances of easy-server running at the same time. This could be deducted by using this command:

Code: Select all

ps aux | grep easy-server
which would show something like:

Code: Select all

pi@raspberrypi:~ $ ps aux | grep easy-server
root      1046  0.1  4.5 146048 43092 ?        Sl   13:38   0:15 node /usr/bin/easy-server --serial=XXXX --access-key=YYYY --password=ZZZZ --host=127.0.0.1
pi       26503 95.5  4.4 134128 42612 ?        Sl   16:16   0:01 node /usr/bin/easy-server --serial=XXXX --access-key=YYYY --password=ZZZZ --host=127.0.0.1
pi       26515  0.0  0.1   3384  1620 pts/0    S+   16:16   0:00 grep --color=auto easy-server
At the same time, there would also be two instances of pm2:

Code: Select all

pi@raspberrypi:~ $ ps aux | grep pm2
root       863  0.0  3.9 133424 37192 ?        Ssl  13:38   0:03 PM2 v4.4.0: God Daemon (/root/.pm2)
pi        9870  0.0  3.7 131028 35824 ?        Rsl  14:31   0:03 PM2 v4.4.0: God Daemon (/home/pi/.pm2)
pi       28059  0.0  0.1   3252  1700 pts/0    S+   16:21   0:00 grep --color=auto pm2
The above situation would correspond with the high CPU load and temperature (and a working Nefit Easy Server).
Killing one of the easy-server instances did not help, another one would immediately come back, believe this is what pm2 does.
Killing one of the pm2 instances by issuing:

Code: Select all

sudo kill 863
removes that instance and by some logic also the related easy-server disappears as well.
What remains is a situation where the nefit-easy server works and where CPU load and temperature are normal.

(To check if the nefit-easy server is working, apart from looking in the Domoticz error log to see "NefitEasy: Error getting http data!", issue the command:

Code: Select all

curl http://127.0.0.1:3000/api/status
to see a reply like:

Code: Select all

pi@raspberrypi:~ $ curl http://127.0.0.1:3000/api/status
{"user mode":"clock","clock program":"auto","in house status":"ok","in house temp":25.3,"hot water active":true,"boiler indicator":"off","control":"weather","temp override duration":0,"current switchpoint":18,"ps active":false,"powersave mode":false,"fp active":false,"fireplace mode":false,"temp override":false,"holiday mode":false,"boiler block":null,"boiler lock":null,"boiler maintenance":null,"temp setpoint":20.5,"temp override temp setpoint":17,"temp manual setpoint":20.5,"hed enabled":null,"hed device at home":null,"outdoor temp":24,"outdoor source type":"virtual"}
)

In short: I can resolve the problem, but what I have not tackled yet is why I had two pm2 instances in the first place. My intention is to 'fully' remove both and follow the instruction in https://www.domoticz.com/wiki/NefitEasy where it talks about "install pm2 to control the service". Hoping to get a consistently working system again.

Any tips on:
- how to fully remove pm2 instances,
- reinstalling one new pm2 one
- if it should be installed under 'pi' in '/home/pi/.pm2' or under 'root' in '/root/.pm2'
are welcome. Other remarks as well obviously.
Have a nice day!
User avatar
FireWizard
Posts: 1893
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by FireWizard »

Hi,

@Domoberry

The issues you had were similar to those described in the second link.
Good they are solved more or less.
Any tips on:
- how to fully remove pm2 instances,
- reinstalling one new pm2 one
- if it should be installed under 'pi' in '/home/pi/.pm2' or under 'root' in '/root/.pm2'
1. Remove pm2.

It should be possible in the following way:

Code: Select all

pm2 kill
sudo npm remove pm2 -g
#test with :
which pm2
and maybe also without sudo.

2. reinstalling one new pm2 one

Why do you want to do that?
I think you can easy install it from: https://github.com/robertklep/nefit-easy-http-server

Run it as "pi" user with: $ easy-server
If this functions well, you can run it as a service, so that it starts up during boot time.

Regards
User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by Domoberry »

Hello FireWizard,

Thank for your guidance!
Why do you want to do that?
Basically, I want to get back to a setup which is identical to what Robert Klep suggested, currently it is not, I have messed up something, which left me with 2 setups (?) of pm2. So, I figured: remove all and do redo it 'the right way'. Which also brought up the last question: where should it go: under 'pi' in '/home/pi/.pm2' or under 'root' in '/root/.pm2' (perhaps I'm talking nonsense here, that would be due to my limited understanding of how things work 'under the hood' in Raspbian Linux.

Out of interest: how do I setup a nodejs program like easy-server as a service? Is that - among others - what pm2 does?
User avatar
FireWizard
Posts: 1893
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by FireWizard »

Hi,

@Domoberry
Basically, I want to get back to a setup which is identical to what Robert Klep suggested
If I read https://github.com/robertklep/nefit-easy-http-server, I don't see that he suggests to install pm2.
If you have a number of nodeJS applications installed, it is a very nice solution, but if you have only one, I think it is unnecessary.

However, if you want to use it, I would run it as the "pi" user, but honestly, I do not have any experience with pm2.
Out of interest: how do I setup a nodejs program like easy-server as a service?
I cannot better describe that, then here: https://tibbo.com/linux/nodejs/service-file.html

This avoids the use of resources by PM2, unless you need it for other applications, but you decide.

Regards
User avatar
Domoberry
Posts: 121
Joined: Tuesday 30 May 2017 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Contact:

Re: High CPU usage Nefit Easy Server (RPI3B, 2020.2, Buster)

Post by Domoberry »

@FireWizard: thanks for your help, I have a correctly running system again with normal CPU load and temperature including support for Nefit Easy, running Raspbian Buster on RPI3B with Domoticz 2020.2 and all auto-starting after a reboot.
200618 CPU normal with nefiteasyserver.JPG
200618 CPU normal with nefiteasyserver.JPG (18.32 KiB) Viewed 1193 times
(I have to admin that the CPU hoovers between 1.5..3%, but this screen shot looks best :-))

Bottom line, nothing wrong with easy-server as expected, just me-myself-and-I who had managed to mess up the setup somehow.

The high CPU load and related CPU temperature was caused by having multiple instances of easy-server running in parallel causing load problems.

I resolved this by removing/deleting/cleaning/uninstalling everything related to pm2 and easy-server, the removal tips you mentioned proved useful as well as the same issue mentioned here https://github.com/robertklep/nefit-easy-core/issues/19.

Then I picked the installation from https://www.domoticz.com/wiki/NefitEasy from "Install pm2 to control the service" onwards (no need to recreate the file nefiteasyhttpserver.sh; it was obviously still there.

I did use pm2 again, even though easy-server is the only node package running (or should I count npm and pm2 itself also?); I just followed the steps in the Nefit-easy wiki.

This might not have been the shortest and most practical solution, experts are likely able to correct the 'multiple instances issue' rather then my approach (delete, clean up and reinstall). But it did the job. This forum is a great resource. Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest