High cpu usage when calling lastUpdate on offline InfluxDB database

I found out that calling lastUpdate in a rule causes very high cpu usage when the influxdb is offline. The problem can only be solved by completely restarting openHAB. I also tested what happens if maximumSince is called, but this does not seem to cause this problem.

Every rule that calls lastUpdate on an offline influxdb creates a thread that uses up a whole cpu core. I have multiple rules that use lastUpdate, so this brought my whole system down several times when I restarted the influxdb.

I was able to reproduce this problem with a new Docker container running a fresh openHAB instance. Also the problem can be reproduced with Linux (Debian) and Windows 10.

Steps to Reproduce

  1. Create an number item NUM_Test that is persisted in influxdb.

  2. Create a rule that can be triggered manually with the following line: var ZonedDateTime lastUpdate = NUM_Test.lastUpdate("influxdb")

  3. Shut down the influxdb.

  4. Trigger the rule.

  5. Run top -H -p PROCESS_ID with the process id of openhab. There should be a rule thread that is now using up a whole cpu core.

Here is a screenshot from top:

I already created an issue on GitHub for this: [influxdb] High cpu usage when calling lastUpdate on offline InfluxDB database. · Issue #19313 · openhab/openhab-addons · GitHub

I’ve created this thread so this issue can also be found in the forum.

This doesn’t address the potential problem with InfluxDB, but in OH 5.0 (I think also 4.3) the Item now has a lastStateUpdate, lastStateChange and lastState property which is independent of persistence (except for the fact that they get repopulated by restoreOnStartup). This should not have any performance issues whatsoever which can help you avoid the current problem.

This should be solved by Persistence extensions: fix potential infinite loop by mherwege · Pull Request #5018 · openhab/openhab-core · GitHub . The problem is not specific to Influxdb.

1 Like

Thanks for the quick solution. I already changed my rules so that they use the rrd4j database for the lastUpdate. rrd4j should hopefully never be offline.

@rlkoshak suggestion is actually the better one when changing rules. There is no need to query any database anymore for the information you are after.

1 Like