Id like to bolt on my experience with slow running rules, which is an intermittent problem. I think I have good indications in my example, that my own problem is related to rule processing in some way.
For the record, Im on an Armv8 processor with 4GB of ram, running off NAND flash and the system is only there for Openhab, so its not doing any other tasks. System is Ubuntu based. A couple of basic facts:
- This has occurred across multiple revisions of Openhab.
- I have rebuilt the system from scratch to see that its not related to a conflict somewhere.
- No OS patches/updates seem to have resolved it.
- I was on MQTT v1, but have updated to MQTT v2 and the problem remains.
- The problem is intermittent, but repeatable.
- There are no errors in my Openhab logs and I have a clean system startup.
- Everything generally runs fine and as expected.
To give a simple example, I have some Sonoff basics that run lights in the house. I also have some buttons that run 433Mhz RF. When you press the button, it sends the RF command to the RF bridge, which sends an MQTT command to Mosquito, after which Openhab has a rule that says “if this command appears from the RF bridge, turn the light on or off, depending on its current state”
rule "Bedside Lights button1"
when
Item RFDataLights received update "811301"
then
if ( gBedroom1.state == OFF ) { gBedroom1.sendCommand("ON") }
else gBedroom1.sendCommand("OFF")
end
If you have used one of these rules, then this rule and all rules like it, process absolutely fine for anything up to the next 5-8 hours (best estimate). However, if the rules havnt been processed for that 5-8 hours, you get a delay of around 20 seconds before the rule runs.
To show this occurring, below is a capture direct from Mosqitto where you can see that the MQTT command arrives at 22:58 and 58 seconds, but Openhab’s logs, shows that the On/Off command that the rule doesnt run until 22:49 and 20 seconds (22 seconds later).
Obviously, because I have to wait 5-8 hours for this issue to occur, its hard for me to get diagnostic data together, but I managed to do another test today, as follows… Can I turn the light on/off in the Openhab interface, while Im waiting for this rule to be processed? e.g. is Mosquitto, MQTT or Openhab (other than rule processing) an issue?
So I opened the Openehab Android app on my phone, and pressed my RF button… The lights didnt turn On at this point. I then turned the lights on in the Openhab Android app, and they came on… then I turned them off again… all of this within the 20 seconds time. After another 10 seconds or so, the lights turned on, which would be the rule being processed.
Ive always noticed that Openhab rules act this way on a reboot of the system (or restart of the Openhab services)… which I assume its something to do with loading of the rules into memory for the first time. As such, I assume that after my 5-8 hours, something (Java or Openhab) has garbage collected the rules out of memory and its performing the same load up process as if you had restarted the system.
Ive attempted in the past to give Openhab more threads to work with as well as more memory for Java, which had no effect, and to be fair, my Openhab isnt doing much in the background anyway (its 98% dealing with presses from commands in the web interface), though its taken me a couple of months to really have a good chance to look at trends occurring and try different things.
Im open to trying any suggestions, though it may be slow going because of the intermittency of the issue. Im also open to being told this is just the way it is, deal with it.
I was wondering if there may be a rule I could create, in that specific rules file, that would force the rules file to be used every 60 minutes or so, to see if that kept the whole rules file in memory… Though I dont know Openhab internal core well enough to know if this kind of keep alive would keep the entire rules file in memory… but Im happy to try it if someone has a suggestion for a rule.
Sorry for the long post, but hopefully its detailed enough to explain the situation. Any thoughts are welcome!
Thanks