Improve openHAB Rules response time

Posted by ads' corner on Monday, 2020-07-06
Posted in [Ansible][Linux][Openhab]

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
- 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
1
2
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.


Categories: [Ansible] [Linux] [Openhab]