History and Logbook peg CPU at 100%

A CPU on a relatively beefy server is consistently pegged at 100% for a while now. I don’t recall when it began, but it wasn’t always the case. I decided to remove the default_config entry and add config back one at a time, and identified that enabling either history or logbook will peg the CPU. I tried repairing the DB but it doesn’t change anything. Functionality seems fine otherwise. Any ideas what could be causing this?

How did you repair your db?

I don’t think there’s anything wrong with the DB, but I ran a repair just to see if it would help. Here’s what I did:

sqlite3 home-assistant_v2.db ".dump" | sqlite3 home-assistant_v2.db.fix
mv home-assistant_v2.db.fix home-assistant_v2.db

Do you want to try moving (backing up) your db and seeing if a newly generated db hss the problem?

Didn’t help. Still seeing about 100% on two CPUs from a couple python processes. Could it be integrations that log a lot of data?

You wouldn’t happen to have recently added an automation with a “while” or a “repeat”, would you?

In fact I did just install a zwave smart switch that I set to turn on at 8pm every night. Is there a known bug with this? I’ll try disabling that and see what happens.

Simple triggered automations are unlikely to be the culprit.

What I would do in your situation would be to disable elements 1-by-1, maybe starting with automations, until the symptom disappear, which will give you the actual culprit.

1 Like

Ok, I disabled a lot of things without any luck, until the very last line in the file - I disabled a packages: include which pulls in snmp-based sensor data from my firewall, which then uses automations to calculate the current bandwidth in and out based on the data. I’m curious though how history and logbook are related to these sensors and automations. Aren’t the calculations done regardless of whether the history or logbook is recording? Or does Home Assistant optimize and only run the calculations when the data is being viewed in the UI if history is disabled?

You’d have to show us the configuration for the sensor and automations. If they use history stats or SQL queries then it relies on the recorder.

The recorder logs continuously, the history and logbook retrieve values from the recorder database when required (i.e. viewed).