Rule causes high load and queue issues

Tags: #<Tag:0x00007faf94554a10> #<Tag:0x00007faf94554948>

Hi there,

today I’ve updated my openhab2 installation to openhab3 Milestone 2 in order to test it out.

I’ve noticed a simple DSL rule causes high CPU load over several seconds and queuing issues with the next call to the rule.

The rule is simple: Get a value, compare and set two items. No problems on openhab2 beforehand.

Here’s the definition, simple eh? :wink:

triggers:
  - id: "1"
    configuration:
      cronExpression: 0/10 * * * * ? *
    type: timer.GenericCronTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: |-
        val Number value = SmartMeter_101670.state as Number

        if (value > 0) {
          Strom_Einspeisung.postUpdate (0)
          Strom_Bezug.postUpdate (value)
        } else {
          Strom_Einspeisung.postUpdate (value * -1)
          Strom_Bezug.postUpdate (0)
        }
    type: script.ScriptAction

Is there anything I can to do improve the situation or did I spot a bug in there?

UPDATE: Using exactly the same rule in a rules file results in no problems. It’s just the definition via the web ui. Strange :thinking:

Best regards & thanks for all your work and support,
Sascha

Very interesting because it has been exactly the other way round in OH2.
The NGRE next gen rules engine has become the default in OH3 now.
I’d suggest to validate you haven’t installed any rules engine or similar and if it’s reproducible open an issue with openhab-core.

Queuing is different in OH3. Under OH2, you could call multiple “copies” of the same rule by multiple triggers, and each would proceed in parallel, maybe at different stages.
Depending what you do, can be blessing or curse.
OH3 runs strictly one “copy” of a rule at a time. Multiple triggers result in an orderly one-at-a-time execution.
Depending what you do, can be blessing or curse.

I see nothing in your rule that should cause it to take over ten seconds to run, which would obviously be a disaster.

Why run every ten seconds? What’s the point, if the source hasn’t changed?

Thank you for your hints and remarks.

I’ve tried a bit and basically got it working with keeping the dsl rules in files and restarting openhab. I’ve tested with snapshot 3.0.0~2009-1.

When putting the rule into the web ui, they sometimes did not work until OH is restarted. Then, when clicking on RUN NOW, the openhab.log outputs (truncated):

java.lang.IllegalStateException: Cannot create a duplicate value 'newState'.
        at org.eclipse.xtext.xbase.interpreter.impl.DefaultEvaluationContext.newValue(DefaultEvaluationContext.java:46) ~[?:?]
        at org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine.createEvaluationContext(DSLScriptEngine.java:143) ~[?:?]
        at org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine.eval(DSLScriptEngine.java:118) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
        at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
        at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) ~[?:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1179) [bundleFile:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1031) [bundleFile:?]
        at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1047) [bundleFile:?]
        at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:305) [bundleFile:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]

Maybe that’s the crulpit? Googeling this reveals some java hints I couldn’t understand.

So for me the solution is: Keep DSL rules in files and dont mess with them in the web ui (don’t disable etc.)

Best,
Sascha

Snapshot 2009 has broken DSL rules. Don’t use this snapshot. The next snapshot sould resolve the problem.

2 Likes

II have the same issue; with the difference that a reboot doesn’t solve the problem.
I saw you alredy hearted my post there, but here’s the link anyhow: openHAB 3.0 Milestone 2 discussion

Thanks, good to know!