robertklep / nefit-easy-core

Core functionality to implementation communications with Nefit/Bosch backend.
MIT License
21 stars 4 forks source link

Memory & CPU load #19

Closed dutchsea closed 5 years ago

dutchsea commented 5 years ago

Hi, I am running the Easy server for about a month now on my Raspberry Pi 3B. It runs very stable and it is a great addition to my Domoticz set-up.

I just notice that that the app uses a lot of CPU time and increases the CPU temperature of the Pi from 50 to 65C. When I start the app in PM2 the "RPi CPU_Usage" jumps from an average of 3% to almost 30% average. In the process overview of the Pi I see the memeory usage by the node process almost continuously at 82% and higher.

I have also another server running in node and that one only increases the "RPi CPU_Usage" with only a few percent.

My question is if these load values for the easy server are to be expected or possibly rather high?

robertklep commented 5 years ago

This has been an issue in the past, but from what I know, it shouldn't be an issue anymore.

Have you tried running the server (temporarily) without PM2?

dutchsea commented 5 years ago

Hi Robert, did i put this question in the right section?

I guess I have not yet tried running the server without PM2. Not sure how to do this... I am no coder, just barely able to run some stuff on a Raspberry pi ;-)

I did stop the service via pm2 stop and thereafter did CPU load dropped to 3% again. Also noticed in the pm2 list that the easy server already has over 180.500 restarts. (Since mid march). Sound like a lot.

Can you help me how to check the version of the server. Mayby i picked an older one?

dutchsea commented 5 years ago

Found how to check the version; its 5.0.2 Also in my case the load isn’t really increasing over time. Its just continiously high in my view.

robertklep commented 5 years ago

If you've had that many restarts, there's something else going on, perhaps a misconfiguration.

To start the server manually:

easy-server --serial='SERIALNUMBER' --access-key='ACCESSKEY' --password='PASSWORD'

(change SERIALNUMBER, ACCESSKEY and PASSWORD to their respective values)

Press Ctrl-C to stop it again.

Alternatively, you could also check the PM2 logs to see if there are any errors being logged:

pm2 logs
dutchsea commented 5 years ago

I stopped the PM2 nefiteasyhttpserver app with id 0 using 'pm2 stop 0' When i start the server manually i get this error:

 { Error: listen EADDRINUSE: address already in use 127.0.0.1:3000
    at Server.setupListenHandle [as _listen2] (net.js:1270:14)
    at listenInCluster (net.js:1318:12)
    at doListen (net.js:1451:7)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '127.0.0.1',
  port: 3000 }

Actually my nefiteasyhttpserver-error.log is an endless list with the same error repeated. I have no idea which process is already using the address. Maybe there are 2 instances of the nefiteasyhttpserver running in parralel?

Still I get all functionality in Domoticz and if I use:

curl http://127.0.0.1:3000/api/status

I get good output:

{"user mode":"clock","clock program":"auto","in house status":"ok","in house temp":21.3,"hot water active":true,"boiler indicator":"off","control":"room","temp override duration":0,"current switchpoint":24,"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":21,"temp override temp setpoint":20.5,"temp manual setpoint":20.5,"hed enabled":null,"hed device at home":null,"outdoor temp":19,"outdoor source type":"virtual"}

dutchsea commented 5 years ago

In my processes (ps aux) overview I see 2 users with the nefiteasyserver:

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       956  0.0  0.2   4604  2572 ?        Ss   apr17   0:00 bash /home/pi/nefiteasyhttpserver.sh
pi        6533  0.0  0.2   4608  2596 ?        Ss   12:27   0:00 bash /home/pi/nefiteasyhttpserver.sh
robertklep commented 5 years ago

Two of the same instances of the process won't work. The first process (PID 956) looks like it gets started automatically at system boot, the second manually (under the regular user, pi).

Perhaps the issue is that the process gets started twice, and the second one keeps crashing because of the EADDRINUSE issue, taking up a considerable amount of CPU time because PM2 keeps trying to restart it.

dutchsea commented 5 years ago

Yes, that is probably the problem. Nothing to do with the server itself. It is likely related to a different way that pm2 is installed on the raspberry pi. I had to issue additional commands to get the nefiteasyserver to restart in pm2 after a reboot of the Pi. Likely this resulted in 2 different users for which the process is started after reboot. Now to figure out how to stop one of them. I think I want to keep the one running under user pi. TY

dutchsea commented 5 years ago

And indeed when I log on as root I see another pm2 instance running the nefiteasyserver:

pi@RPiMost:~ $ pm2 stop 0
[PM2] Applying action stopProcessId on app [0](ids: 0)
[PM2] [nefiteasyhttpserver](0) â
âââââââââââââââââââââââ¬âââââ¬ââââââââââ¬âââââââ¬ââââââ¬ââââââââââ¬ââââââââââ¬âââââââââ¬ââââââ¬ââââââââââââ¬âââââââ¬âââââââââââ
â App name            â id â version â mode â pid â status  â restart â uptime â cpu â mem       â user â watching â
âââââââââââââââââââââââ¼âââââ¼ââââââââââ¼âââââââ¼ââââââ¼ââââââââââ¼ââââââââââ¼âââââââââ¼ââââââ¼ââââââââââââ¼âââââââ¼âââââââââââ¤
â nefiteasyhttpserver â 0  â N/A     â fork â 0   â stopped â 27125   â 0      â 0%  â 0 B       â pi   â disabled â
â server              â 1  â 1.6.8   â fork â 974 â online  â 0       â 26h    â 0%  â 55.1 MB   â pi   â disabled â
âââââââââââââââââââââââ´âââââ´ââââââââââ´âââââââ´ââââââ´ââââââââââ´ââââââââââ´âââââââââ´ââââââ´ââââââââââââ´âââââââ´âââââââââââ
 Use `pm2 show <id|name>` to get more details about an app
pi@RPiMost:~ $ sudo su
root@RPiMost:/home/pi# pm2 list
âââââââââââââââââââââââ¬âââââ¬ââââââââââ¬âââââââ¬ââââââ¬âââââââââ¬ââââââââââ¬âââââââââ¬ââââââ¬âââââââââââ¬âââââââ¬âââââââââââ
â App name            â id â version â mode â pid â status â restart â uptime â cpu â mem      â user â watching â
âââââââââââââââââââââââ¼âââââ¼ââââââââââ¼âââââââ¼ââââââ¼âââââââââ¼ââââââââââ¼âââââââââ¼ââââââ¼âââââââââââ¼âââââââ¼âââââââââââ¤
â nefiteasyhttpserver â 0  â N/A     â fork â 956 â online â 0       â 26h    â 0%  â 2.5 MB   â root â disabled â
âââââââââââââââââââââââ´âââââ´ââââââââââ´âââââââ´ââââââ´âââââââââ´ââââââââââ´âââââââââ´ââââââ´âââââââââââ´âââââââ´âââââââââââ
 Use `pm2 show <id|name>` to get more details about an app
dutchsea commented 5 years ago

I stopped the root instance using:

sudo pm2 unstartup -u root

Rebooted and everything is fine now; nefiteasyserver only running under user pi and CPU load now back from 33% to less than 2%

robertklep commented 5 years ago

Nice! Good you hear your solved it 👍🏻