Increased CPU usage over time

Hello dear Home Assistant community!

I stumbled to a behavior I cannot really dig down what the cause of this is. I have Home Assistant running in WSL2 on my Windows machine. For the first weeks it run just fine with basically 0% CPU usage. I added some automations and integrations here and there and it was still fine. But suddenly I have weird CPU spikes and they even get higher over time.

image
At 19:00 is where I restarted Home Assistant. As you can see, the CPU usage grew over time.

I can already tell, this is coming from Home Assistant because when it is not running, the CPU is basically doing nothing. I tried to narrow it down to the source by disabling all automations and even disabling integrations. But they had no effect. Not even upgrading Home Assistant to the latest version using Python 3.9.

I even used py-spy to inspect it and I noticed that http/client.py is using most of the CPU time. But why? Any ideas?

I am even to the point considering wiping all data of Home Assistant and starting everything from scratch. But would be cool if somebody has an idea what’s the cause of this before I do that :slight_smile:

Also this what the log is outputting repetitively:

2022-03-22 12:27:31 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/homeassistant/components/dhcp/__init__.py", line 287, in async_discover
for host in await self._discover_hosts.async_discover():
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/aiodiscover/discovery.py", line 153, in async_discover
neighbours = await sys_network_data.async_get_neighbors(hostnames.keys())
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/aiodiscover/network.py", line 173, in async_get_neighbors
neighbors = await self._async_get_neighbors()
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/aiodiscover/network.py", line 186, in _async_get_neighbors
return await self._async_get_neighbors_ip_route()
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/aiodiscover/network.py", line 229, in _async_get_neighbors_ip_route
for neighbour in await loop.run_in_executor(None, self.ip_route.get_neighbours):
File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/pr2modules/iproute/linux.py", line 319, in get_neighbours
return self.neigh('dump', family=family, match=match or kwarg)
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/pr2modules/iproute/linux.py", line 1072, in neigh
ret = self.nlm_request(msg, msg_type=command, msg_flags=flags)
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/pr2modules/netlink/nlsocket.py", line 403, in nlm_request
return tuple(self._genlm_request(*argv, **kwarg))
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/pr2modules/netlink/nlsocket.py", line 907, in nlm_request
self.put(msg, msg_type, msg_flags, msg_seq=msg_seq)
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/pr2modules/netlink/nlsocket.py", line 646, in put
self.sendto_gate(msg, addr)
File "/mnt/c/Users/DeDelner/homeassistant/lib/python3.9/site-packages/pr2modules/netlink/rtnl/iprsocket.py", line 87, in _gate_linux
return self._sendto(msg.data, addr)
OSError: [Errno 95] Operation not supported

Maybe try to “remove” that “integration” that you use to see Windows" CPU-load " in HA …

There are no such thing as “suddenly” , there are always a “point in time” :slight_smile: …( Network device failed, something became “unavailable”, something was “added/changed” etc. etc.

I.E Seems like you are using some “integration” to retrieve information from i.e Windows, i would start there(remove !), then monitor you “Cores” in window-taskmanager, you can find out which “individual” core/cores your HA instance Uses

Yeah I just did that, but the behavior continues :frowning: I did some further investigations…
I used a binary sensor that is pinging my PC to know if it’s turned on or off. And when I turned that off, the CPU was basically at 0% all the time.
And then I changed my binary sensor to a device tracker as I thought might help the problem. It did sort off, but I am still having those spikes. I just wonder, what is Home Assistant doing that causes those big spikes

Compare your logbook entries at the time of those high points?

again, it seems to me it’s a “card” in HA, showing the total of your CPU’s “cores” on your windows machine, correct me if im wrong, still in windows you have a nice easy overview of your individual cores, and therefore can see if these “spikes” comes from the “core/cores” you dedicated to HA
… and if you don’t see “same” spikes in your windows “taskmanager” at all, i would say “they don’t really exist” … so i would still “focus” on the “integrations/sensor” you are using to show this in HA/Card ( i.e you also have quite alot in beginning of this Pic (about 1 each 3rd minute) then it drops to half )
IF these “spikes” actually comes from the CPU-Cores you/windows have dedicated for your VM, it could still be your tracker/card, as it “needs” access to the windows system … it doesn’t do that just by picking it up from the “bottom” of your system,… from HA it has to go through your network(unless this “integration” is capable of reading your windows system through a “Virtual Machine” APP) im pretty sure it can’t … so if your “Network/Network settings” is not the most “efficient setup” , and the integration+card is neither , you will get some “performance” tops" every time this integration is “calling”… tops depending on what it’s calling and from where ( local in HA or somewhere in your network)
Again, i assume you did solve the “Increased CPU usage over time” ? , but then you added the/some tracker( i don’t know which), And those “spikes” might not be the same as you saw before(with the binary) , as the 2 pics(1st n 2nd)
So skip the “Tracker” as you call it, monitor your CPU on your Windows / Compare, and do check whether the “ERROR” also is gone

  1. your binary sensor was not a success
  2. your added “Tracker” or what ever you mean you use to “monitor” your windows machine and the Card used for that ???
    You still have “sorted” out when or what, i know, but you have to “exclude” that it’s not caused by the “things” that you “integrated” to monitor …

PS: Don’t tell me you also have “Speed-Monitor” installed in HA, as these are not only consuming your network band, but also your memory/cpu :slight_smile: