How do you do performance optimization? Which rules take the most CPU? Which has the most RAM? Where can I improve my system?

  • Platform information:
    • Hardware: INTEL Celeron N3150, 8GB RAM
    • OS: Synolgy DSM 7.1.1-42962 Update 6
    • Java Runtime Environment: docker container openhab/openhab:4.0.2
    • openHAB version: 4.0.2

Hi experts,
I have quite a big OpenHab system running now after 5 years of continuous integration. Now I would like to optimize the performance of the system. I would like to find out which things, bindings, or rules are challenging the resources of my system the most.
But I absolutely have no idea what could be the best way. On my Android cellphone, I can check which apps have used the battery the most. Is there something like this available, or is there some checklist I can work through to optimize my system for performance?

In the moment, I have:

  • 183 things
  • 1432 items
  • 46 rules (most of them quite complex, for example, one rule for all window and door sensors, etc.)
  • 31 widgets
  • 13 bindings

In the log, I only have these errors and warnings:

2023-09-15 09:50:12.788 [WARN ] [ty.util.ssl.SslContextFactory.config] - Trusting all certificates configured for Client@2235cf4c[provider=null,keyStore=null,trustStore=null]
2023-09-15 09:50:12.789 [WARN ] [ty.util.ssl.SslContextFactory.config] - No Client EndPointIdentificationAlgorithm configured for Client@2235cf4c[provider=null,keyStore=null,trustStore=null]
2023-09-16 21:05:50.988 [WARN ] [.transport.servlet.ServletController] - Can't find the request for http://192.168.0.2:9080/rest/events/states's Observer 
2023-09-16 21:05:51.760 [WARN ] [.transport.servlet.ServletController] - Can't find the request for http://192.168.0.2:9080/rest/events's Observer 
2023-09-16 21:05:51.789 [WARN ] [.transport.servlet.ServletController] - Can't find the request for http://192.168.0.2:9080/rest/addons/services's Observer 
2023-09-16 21:07:12.637 [INFO ] [ng.homematic.internal.misc.MiscUtils] - Datapoint name '${sysVarAlarmZone1}' contains invalid characters, new Datapoint name '__sysVarAlarmZone1_'
2023-09-16 21:07:12.639 [INFO ] [ng.homematic.internal.misc.MiscUtils] - Datapoint name '${sysVarPresence}' contains invalid characters, new Datapoint name '__sysVarPresence_'

In the moment openhab it uses 1.6 GB RAM from 8 GB. All services in total use 42% RAM.
Total CPU use is 13% when the system start is done.

I would appreciate any hints on how to optimize my system.

Given the relatively light system requirements for most Home Automation instantiations, I recommend spending at least as much if not more effort on making your system optimized for human consumption. If you make your rules or config really complicated to use 1% in CPU you’ve imposed a pretty significant burden on future @helipus when that guy needs to update and maintain the system.

I’d say, based on your numbers, you have an above average sized system. Not particularly large.

the warnings are nothing to worry about. You have an HTTP Thing configured to trust all SSL certificates and you happened to have MainUI open during an OH restart.

The INFO log statements are from Homeatic and since they are INFO they are not problems.

There’s not a whole lot you can do here. As a Java application it will grab memory as it’s needed but generally never gives any back. You should see the RAM usage ramp up to a certain point and then level off. If it never levels off there is a memory leak and you OH will crash with an OOM exception at some point.

Running in a container is going to significantly increase the amount of memory so running on bare metal will reduce memory requirements, but that really isn’t an option on Synology.

For the CPU you’ll need to identify what services are actually using CPU to see if OH is even contributing significantly to the overall usage.

Then you’ll have to hook up a profiler and/or enable logging for Rule events to see which rules (if any) are taking the most amount of time to run. Once you identify those then you can look at optimizing the code.

But if you have over 50% RAM free and 87% CPU is idle, you don’t have a performance problem. It can be a fun problem to explore but overall you’ll be imposing a burden on future you to solve a problem that doesn’t actually exist. That’s not a great tradeoff.

1 Like

Hi @rlkoshak,
thanks as so often for your advice.

Since there is no easy way to determine exactly which rules consume the most resources, I will follow your advice and not invest any time in further optimisation.

As far as maintainability is concerned, I have built a completely new system with OpenHab 4 by making everything except the widgets and the things file-based. (OH2 I did everything filebased, OH3 I tried the GUI approach, OH4 I went back to filebased. I so much like the chance to search and replace over my whole configuration.)
Very sorted with a lot of documentation. Everything I didn’t need in terms of channels or items was removed, as I had tried out a lot in OpenHab 3. I also restricted myself much more with the bindings.
All rules are now written with JavaScript (ECMAScript 2022+).
My items are all named with a system as I learned it from you, so that I can execute various rules on the item names.
I have also started to define global functions and create them in my own library so that I have little repetition in the code.

Thank you.