Rule Takes a Few Seconds to Fire the First Time

Someone told me that this is a known issue, but I found a work around that seems to alleviate this problem, and I thought I would share it for anyone that might benefit from it.

Just add a “System started” rule in each rules file, if it does not already contain one.

This is an example:

rule "System started"
when
    System started
then
    logInfo("info", "Loaded model 'file_name.rules'")
end

It seems to make it so that all of my rules fire right away. It seems to be working so far at least.

1 Like

A few seconds from what?

  • start the system
  • change a rule
  • ???

Changing a rule or starting the system. Basically the first time a rule is ran, it always takes a few seconds longer than normal. Sometimes up to 10 seconds longer.

I think it has something to do with loading the rule file itself, because this work around seems to get all the rules in the same file loaded, so that they run instantly the first time.

After start and after changing there is a info in operhab.log

2017-11-03 14:52:59.252 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘demo.rules’

Yes thats takes some seconds, but your rule doesn’t speed up.

Seems there are mixed results on this?

It has nothing to do with the logInfo, it has everything to do with actually running a rule in the rules file itself. The call to logInfo is just there for me to visually see that it ran. The call to logInfo could be removed and do nothing but run the rule, and it would still serve its purpose of having a rule run right away.

Having a rule run right away seams to remove the delay I have been getting for any of the other rules that have yet to run in the same rules file.

I’m a bit confused right now. naming your rule after the file the rule is in (or another file with another rule) doesn’t have any effect at all. The rule name is just that - a name.
or do I miss the April’s fool here? :wink:

I don’t even know what you are talking about. I never said anything about a rules file name. The only thing that is important for this, is that a “System started” rule is added to every rules file, if it does not already contain one. Nothing more, nothing less.

1 Like

Now I understand - and you’re absolutely right. This one did the trick and I don’t have to worry about delays anymore - of course the only downside is, your system takes a wee bit longer to start but then you’re done forever and rules get processed even faster, yes.

1 Like