My setup is becoming more and more complex, with more rules and items… Since then I have groupped rules by item type (weather.rules, wifiled.rules, etc…). However now I’m wondering which is better… So for example I have a rule which runs when an item changes.
rule "Test rule"
Item Temp changed
// Do whatever...
Now if I want to use that trigger somewhere else, where it purpose will be different, is it a problem that I have multiple rules which is triggered by the same item/event? Is it better to have just one rule with this trigger and do everything there (even if this breaks the readability of the rules) or is it not a problem that I have 2-3-4 rules which triggered by the same thing. Does this affects the perfomance of the system or can anything else happen by this?
It’s not a problem - provided that you don’t expect those rules to run in any particular order, or even one at a time.
One giant rule-them-all would mean marginally less system overhead, and in many cases avoid a little duplication of your own code. But I would not worry about the small effect, maintainability is more important.
Thanks! I thought the same…
I find that, along with large rule files (many rules in a file) very slow to compile and test. One file I have takes around 15 to 20 seconds before it’ll trigger.
Many files, small rules works for me.
I didn’t saw this before, but I try to do the same and reduce file size, this is also good for readability I think… I have around 50 lines of rule / file
Yep, I’m sure there’s a payoff between optimising for startup times and for normal service.
I recall OH1 could get quite sluggish on the first-time execution of each rule, so one big rule could get over that hump ‘apparently’ quicker. Same processing really, less noticeable ‘events’.
Not something I’ve noticed with OH2 although the box does have more horsepower, so it might well still be relevant. I wonder if SD card filesystem could have an impact here too.
There is one minor caveat. As long as all of the Rules triggered by that same event run quickly (i.e. no waits or long running calls to execute a script or make an http call) you will be fine. As long as the Item Temp isn’t changing faster than it takes for the Rules to complete before the next event you will be fine.
But if those turn out not to be the case, you might run into a situation where you run out of Rules execution Threads. You only get five threads by default. As long as you avoid a backlog of Rules waiting for their turn to run you will be fine. But if things happen too fast and/or Rules take too long to run then you can run out of threads and all your Rules come to a halt.
This is unlikely to happen in the example you described, but it is something to be aware of before you create 10 Rules that trigger on the same event and five of them take 20 seconds to run.
Thanks! For now, I just thought of some sample rules which sends a command to an item. But this is good to know, thank you very much!!