Skip to content

Improve openHAB Rules response time

By default, openHAB only starts 5 threads to deal with execution of Rules. That's not a lot, and if all threads are busy, rules have to wait until a slot is free. This results in slow Rule response time.

This can be improved.

 

The thread pool used by openHAB is defined in "/etc/openhab2/services/runtime.cfg". Adding a line with "org.eclipse.smarthome.threadpool:ruleEngine=" will define the new number of threads used for the Rules engine. Rolling this out using Ansible, I use a "lineinfile" Task to update the configuration file:

- name: Set number of Java threads used for Rules
  lineinfile:
    dest: /etc/openhab2/services/runtime.cfg
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
    state: "{{ item.state }}"
  loop:
    - { regexp: '^org.eclipse.smarthome.threadpool:ruleEngine=', line: 'org.eclipse.smarthome.threadpool:ruleEngine=20', state: present }
  notify:
    - restart openhab2

Most likely this config entry will not be there in the beginning, then the default of "5" is used. Adding this setting, and restarting openHAB results in "20" threads. Verification by using "/usr/share/openhab2/runtime/bin/client":

openhab> config:list "(service.pid=org.eclipse.smarthome.threadpool)"
----------------------------------------------------------------
Pid:            org.eclipse.smarthome.threadpool
BundleLocation: null
Properties:
   discovery = 5
   ruleEngine = 20
   safeCall = 10
   service.pid = org.eclipse.smarthome.threadpool
   thingHandler = 5
openhab> shell:threads --list | grep ruleEngine | grep -v grep | wc -l
20

The system is more responsive now, but with added workload the "20" might not even be enough in the future.

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options