I’m running HA on an Android device using termux and udocker, so I acknowledge that this is not supported. So no help is expected.
CPU usage is normally very low (one core < 20% utilized). Occasionally after a restart CPU usage is notably higher (3+ cores ~100% utilized) and remains at a consistently high level – even after running for hours. Usually a restart returns the system to a lower CPU level. It really does seem to be that there are two levels, determined by something at system startup. The processes, from ps, using high CPU are “python3 -m homeassistant --config /config”. No news there.
I have installed the Profiler integration and used “Log current asyncio tasks”, “Log event loop scheduled” and “Log thread frames” to create logs in both high and low cpu usage situations. I see no notable, consistent differences between the log output.
Other than the CPU utilization, I see no differences in function.
Any suggestions for using Profiler or other tools to diagnose what is happening?
It’s not a critical problem for me – it usually takes only one or two restarts to return the system to an ultra-low cpu usage state (where it remains until a restart). But if I can spot a problem, maybe it is useful to the community.
Try looking at the CPU load for a APP/Addon one at a time, located in the APP/Addon area. If it seems high, try stopping it for a few minutes, then restarting it. Watch CPU and memory it consumers. That should help you pin point a possible hog of CPU or memory.
What Router do you have? I have a OpnSense, when I upgrade my router (and reboot it), I also have a high usage in Home Assistant. I restart of Home Assistant solves the problem.
In my case I shutdown Home Assistant, upgrade OpnSense, reboot OpnSense and than I start Home Assistant.
I disabled every integration and still have the same problem! Might even be worse – so far every restart has ended up with high CPU utilization. Will continue restarts to see if that changes. Previously it was maybe 50/50 – or possibly slightly more likley that it would be low CPU.
I guess I’ll also create a new HA configuration and see if I have the problem with a fresh setup.
@Ronny1978 It’s a TP-Link Deco. I’ve never sensed any relationship between HA and the router. I’m not sure I’ve rebooted it recently, but will try that.
I tried with a fresh configuration and had the same result – sometimes it starts and has low CPU utilization, sometimes it ends up with high CPU utilization.
I didn’t even go past the Welcome screen on HA, so presumably very little was happening!
Any way to test and/or fix that? I’ve seen that mentioned in other high cpu posts – but it’s not clear what to do about it. I don’t think I can run “ha dns options --fallback=false” at my normal prompt, since home assistant is run in a udocker “container”. Can I edit a configuration file directly?
I don’t know if this is helpful information, but if I enter a shell within the container to look at /etc/resolv.conf it shows:
nameserver 8.8.8.8
nameserver 8.8.4.4
Profiler does not appear to be reporting on whatever it is that is consuming CPU. The results I see (via cachegrind or callgrind) appear to be very similar in the low CPU and high CPU cases. I’ve been running the profiler for 300 seconds – the resulting total ns is always around there (e.g., 301,503,025,573 (100.0%) PROGRAM TOTALS).
PID TID USER PR NI CPU% S VSS RSS PCY Thread Proc
25440 25869 u0_a220 20 0 12% R 631808K 375428K fg SyncWorker_6 python3
25440 25870 u0_a220 20 0 12% R 631808K 375428K fg SyncWorker_6 python3
25440 25871 u0_a220 20 0 12% R 631808K 375428K fg SyncWorker_6 python3
Not always the same SyncWorker_n – the next run of HA it was 1.
There may be a relationship with the number of cores I let HA use. I was limiting it to 4 of 8, and would get three cores at ~100% (each is 12% 100/8). When I let it use all 8 cores, I know have 7 threads using ~100% cpu.
PID TID USER PR NI CPU% S VSS RSS PCY Thread Proc
27501 27978 u0_a220 20 0 12% R 762148K 373932K fg SyncWorker_5 python3
27501 27982 u0_a220 20 0 12% R 762148K 373932K fg SyncWorker_5 python3
27501 27981 u0_a220 20 0 12% R 762148K 373932K fg SyncWorker_5 python3
27501 27977 u0_a220 20 0 12% R 762148K 373932K fg SyncWorker_5 python3
27501 27980 u0_a220 20 0 12% R 762148K 373932K fg SyncWorker_5 python3
27501 27983 u0_a220 20 0 12% R 762148K 373932K fg SyncWorker_5 python3
27501 27979 u0_a220 20 0 12% R 762148K 373932K fg SyncWorker_5 python3
27501 27501 u0_a220 20 0 0% S 762148K 373932K fg python3 python3
15615 15615 u0_a220 20 0 0% S 35640K 2316K fg sshd-session /data/data/com.termux/files/usr/libexec/sshd-session
Yeah so it’s definitely HA/core related and the profiler should catch that. I’m not a big fan of it though. It crashes if you try to use it for memory for example.