Allow extra execution threads for use on large systems hosted on powerful hardware #5040
Comments
You can set the thread pool sizes as it is already done in demo configuration
The protected final ScheduledExecutorService scheduler = ThreadPoolManager
.getScheduledPool(RuleEngine.class.getSimpleName()); Have you ever tried using
|
@maggu2810 Thanks very much for the prompt reply, I wish I'd posted before doing a lot of work rewriting my rules. Which files are these settings in? |
I don't know the directory layout of openHAB. But I am pretty sure that service is some cfg file that already contains some lines starting with |
A quick bit of detective work reveals /var/lib/openhab2/config/org/eclipse/smarthome/threadpool.config discovery="5" putting HOWEVER: Is there anyway of checking that anything has changed other than trying to run 16 or more rules at once? |
Caveat: not sure changing these is recommended. You can set these in
In the karaf console, you can type the following to see the values.
|
@mhilbush Thanks Mark, I have added the section to runtime.cfg, and changes are reflected instantly in both /var/lib/openhab2/config/org/eclipse/smarthome/threadpool.config and also the Karaf Console. org.eclipse.smarthome.threadpool:ruleEngine=NN`` Do you think it Is worth getting this option documented or should I now just close this issue? |
@sheppy99 I don't really know. Maybe you could let this config run for a while, then report back here if you see any changes (improvements or degradation) in performance. |
@sheppy99 I actually don't think that you can change the rule threads using that config parameter. |
@mhilbush That's interesting. I've just started up my old Pi3 running OH V2.2 and it doesn't have a ruleEngine parameter in Karaf as a default, so if it is relevant then I guess there is a built in value that doesn't show up until its overridden. I also just tried changing it to 1, and then to 0 and a test rule still ran.
Maybe it changes in Karaf immediately, but doesn't affect the rule engine until a reboot |
From what I can see, it doesn't look like it can be changed from the default. |
OK, Further googling leads me to https://community.openhab.org/t/handler-takes-more-than-5000ms-for-processing-event/22158/20 which mentions adding which seems to have become the default, so I've changed it to 15 and will see what happens. First impressions seem like slightly more memory is in use after a reboot, which suggests that something may have happened from one of the 2 parameters. I'll update this thread in case anything happens, and hopefully someone else can add anything relevant when Europe wakes up in a few hours. Thanks for your help Mark @mhilbush and Markus @maggu2810 |
@sheppy99 As you already find it yourself: https://github.com/eclipse/smarthome/blob/38abcbb/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/ThreadPoolManager.java#L55 @mhilbush The configuration key - values are put to an internally hold map here: https://github.com/eclipse/smarthome/blob/38abcbb/bundles/core/org.eclipse.smarthome.core/src/main/java/org/eclipse/smarthome/core/common/ThreadPoolManager.java#L82 |
Also please note the observations regarding rule execution during *.rules file parsing reported here: #4716 (comment) |
Note that this is only an issue when editing and reloading rules. On an idle system, this should be unrelated.
to your
Can you say whether it seems to be queued, because some other rules are already actively executed at the same time or does it even happen, if nothing else is running? |
Not sure why I missed that. I had set DEBUG on |
@sheppy99 Sorry for confusing you last night.
I think this is because there's a timeout on the threadpool that removes threads from the pool after a time period (currently 65 seconds). So, you needed to wait more than 65 seconds for any existing threads to be timed out. I just ran a test with 8 rules all triggered by the same item. Setting the RuleEngine parameter definitely constrains the number of rules that will run concurrently. Note that when you lower the RuleEngine parameter, the change takes effect, but only after the timeout of any threads in the pool above the new RuleEngine value. |
Thanks everyone for the replies. |
To update this I've been running with the revised settings for 5 days now and everything has been running smoothly. My settings in runtime.cfg are:
Could the developers explain what the difference between the 2 settings are please, and maybe if this continues to prove a useful change can this be added to the documentation? |
The |
For tasks which are scheduled from a ThingHandler (like script execution from the Exec binding or periodic polling) there is a separate thread pool |
@htreu Thanks very much for that, it explains a lot. |
Yes, we should add documentation for this. Please see #5081. |
Yes this can be closed, thanks everyone for your help! |
I've just migrated a large OpenHAB system from 2 x Raspberry Pi's onto one i3-7100u mini PC with 8GB RAM and after consolidating the rules from both machines I ran into issues with rules taking many seconds to fire due, I think, to awaiting spare program threads to use. Most of the time the Java process uses less than 5% of one CPU core and less than 12% memory, yet I seem to run out of resources for rules. There are no warnings in the log for this condition, rules just don't trigger for several seconds. I'm currently running Snapshot 1203 in case its relevant and had the same issues in V2.2 stable
As an enhancement can a setting be added to expand the resources of OpenHAB?
Apologies if I have posted this in the wrong place!
The text was updated successfully, but these errors were encountered: