High CPU usage after upgrade to 2023.4.0

Hi,
Today I upgraded my HA Docker setup to 2023.4. I have done everything as always. After update my CPU usage has gone up to around 30 – 35%, when before update it was always under 10%.

Before update, I read the changelog and I understand that there was some rather big database optimization, but this notification from HA saying “Database optimization in progress” is already gone, so I guess it should settle down already.

I am using external MariaDB database and as you can see it is causing high cpu usage, but HA cpu usage is also abnormally high.

Is this possible that database optimization is still ongoing even without this “database optimization” notification?

I have not tried restarting everything yet, because I don’t want to interrupt something.

Yes. There is some background migration of old data after the schema update completes. Advice we received during beta testing:

Also once you update and the schema migration finishes there will still be a bit of increased I/O + cpu for a few minutes (longer if you have changed the keep days default). So be sure to wait a bit before measuring cpu etc

1 Like

Thanks for the info.

Waiting a little longer seems to solve everything. More like 3.5 hours longer, but maybe that’s because I set purge_keep_days to 90. CPU usage looks normal to me now, around 5 – 8%.

You are mentioning “minutes”, but my CPU stays high for 5-6 hours already. Any ideas?

How big was your database?

13 Gb. The issue was also posted in the thread dedicated to the 2023.4 release, together with an issue with my SQL sensors returning “no result” after the update. An other user saved me, pointing out that the SQL sensors needed updating. Once I did that, everything was back to normal. Posted the solution over there, just in case someone else encounters the same issue. Thanks!

After updating to 2023.04 about 12 hours ago, Home Assistant seems to be slower than before. Even the gauge animation isn’t smoove anymore.

Got InfluxDB installed.

Any suggestions what to do?
Downgrade via backup back to 2023.03.06?

Apologies if this is a completely different issue, but my CPU usage was like yours after the upgrade - up to around 30% from the previous 5%
I’ve since discovered that I had several bits of sql (running via the sql integration) that were looking for the “entity_id” in the states table - this has now changed and you need to use the “metadata_id” (which you can get from the states_meta table).
I had 3 of these set up, and correcting the sql has dropped my cpu usage back down to a fairly static 5%.

Here an example of an updated bit of sql.

select max(cast(state as float)) high from states where metadata_id="400" and datetime(last_updated_ts,'unixepoch') >= date('now', 'start of day') AND state IS NOT NULL AND state NOT IN ('unknown', 'unavailable') 

For info, my db is less than 1GB - I don’t think that would be considered large? The CPU usage was still high after 18hours, but lowered at the exact point I fixed the sql.

Here are the CPU graphs. I don’t think I need to point out where the upgrade took place. :slight_smile:


3 Likes

bdraco mentioned that large databases can take hours to migrate in the release thread.

Agree, but the actual issue were the SQL sensors going haywire after the database changes. @Wilber’s post above is spot on in showing what’s been going on and how to correct the SQL queries.

1 Like

I don’t know if only the size of the database matters. I completely killed my database and my CPU usage is still high. Waited almost more than an hour.

In my case after upgrade to 2023.4.0 HA is working with db more than 24h, my db is about 2,2GB handled by mariadb, CPU from 25% used, now is oscilating 50-60%, SSD read since upgrade grew by 1,5TB, ssd write by 60GB and it is still working on that db.

Im at 4.1 and the CPU still high after 16 Hour. The sql server is on different machine and it take about 30min to see the CPU high there. Now SQL server cpu seems settled by home assistant still using more that double cpu. I dont think it has anything to do with DB anymore. 3% vs 8% now.

image

Well managed to fix after disable localtuya, full OS reboot, reenabled localtuya. (There is some error in log about localtuya)

image

I hope everyone else got fix.

I have the same issue, high cpu after the april update. It’s been a few days (a week actually), i am on version 4.3 atm en did a full reboot. But CPU utilization of InfluxDB remains high, never experienced this before.

I do not have sql sensors or the like, hoping for a fix in a future version :slight_smile:

1 Like

Same issue here. I can’ t find the source of the problem. After all my automatons were taking 10’s of seconds to fire, I gave up and rolled back to 2023.3.6

2 Likes

I made purge of my database into 1 day, so it removed all history from database and reduce database size to 45MB and then CPU use went down but it is still higher than on 2023.3.6, in my case I also installed add-on glances to deeply check what is consuming my CPU - but nothing special can find, so this add-on also is taking some “cpu power”

1 Like

I’m not familiar with Glances, but perhaps you could just add the following in your configuration file. I see you’re using Grafana too.

# create new sensors for HA hardware system monitoring
- platform: systemmonitor
  resources: 
    - type: processor_use
    - type: processor_temperature
    - type: memory_free
    - type: memory_use
    - type: memory_use_percent
    - type: disk_use_percent
      arg: /
    - type: disk_use
    - type: disk_free
    - type: throughput_network_in
      arg: eth0
    - type: throughput_network_out
      arg: eth0

From presented only “processor_use” i “memory_use_percent” is working - my installation: Generic x86-64 HAOS.
Glances is nice but it is taking quite huge resources.

For me the killers were InfluxDB and Grafana, since I removed them it’s all back to normal. My disk was 100% busy, response times went up to 45000 micro seconds, now is below 10 again. Did not install the addins back as I use HACS cards instead of grafana lately. Hope it helps some of you.

1 Like

I also suffer from high CPU usage since 2023.04.

Got InfluxDB and Grafana installed.

Does anyone know how to find out what causes the CPU Usage?