Cron rules , are they combined by OH or not?

I was thinking about how rules are triggered in case you have several ruleset for different things which uses Cron triggers.

When you have multiple stuff there is definitely later or earlier situation that you are using Cron at same time at various rules.

How OH is handling these? is it running all rules as one because same cron time or they are run separately?
If separately, isnt it performance killer in case you have 20 rules which runs at midnight?

just thinking about this for some unknown reason.
:slight_smile:

Thanks

Separately but OH is limited to the number of threads (5 by default IIRC).

See this thread and the threads it references (depending on how much detail you want :wink:). The short version is:

  • the rules triggered by cron are run separately
  • until recently, there were 2 threads for executing cron rules (i.e. 2 cron rules could execute concurrently)
  • the number of threads was changed from 2 to 10 a short time ago
  • you can change this to whatever you want
  • if there are more rules to execute than there are threads, rules will queue until a thread is available

that’s interesting,
what happends with 11th rule? because time will pass out, that rule will or will not be triggered?

It will wait then execute when one of the 10 finishes.

So, if your rules execute quickly (i.e. no Thread::sleeps, etc.), that 11th rule will execute pretty quickly. As you might imagine, when the thread count was 2, it was a very different story…

Edit: I updated my post to reflect that rules will queue until a thread is available.

ok so they stack and will be triggered… good to know

thing is, after some time and some extended rulesets you will loose pretty quickly overview how many rules are running at which time, so that was my thinking about, more like best practise.

I have a few rules that run daily and I have cron staggered them so that they don’t run concurrently.
For example the astro binding runs at 30s past midnight. There maybe other bindings with daily tasks. Just so that I don’t get a bottleneck, I have staggered the rules. It doesn’t really matter at what time they run as long as it’s between 12 and 1am because of the daylight saving changes.

1 Like

Vincent has the best practice. Try to stagger your cron triggers Rule when you can. If you can’t and 10 isn’t enough, increase the thread pool size. Even an RPi should be able to handle way more than 10 Rules running at the same time, assuming the Rules are not doing something unusual like blocking or implement a tight loop or the like.