# Memory usage of OH4 on RPi 4 model B within Docker

**URL:** <https://community.openhab.org/t/memory-usage-of-oh4-on-rpi-4-model-b-within-docker/155802>\
**Category:** Beginners\
**Tags:** memory\
**Created:** [May 5, 2024, 3:21pm UTC](https://community.openhab.org/t/memory-usage-of-oh4-on-rpi-4-model-b-within-docker/155802 "2024-05-05T15:21:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mu88](https://community.openhab.org/user_avatar/community.openhab.org/mu88/32/102048_2.png) [@mu88](https://community.openhab.org/u/mu88)\
**Post date:** [May 5, 2024, 3:21pm UTC](https://community.openhab.org/t/memory-usage-of-oh4-on-rpi-4-model-b-within-docker/155802/1 "2024-05-05T15:21:56Z")

</div>

- Platform information:
  - Hardware: Raspberry Pi 4 model B (4 GB RAM)
  - OS: Raspberry Pi OS / x64 / 12 (bookworm)
  - Java Runtime Environment: OpenJDK 64-Bit Server VM version 17.0.9+9-Debian-1deb11u1
  - openHAB version: 4.1.1 (running in Docker)
  - ConBee 2 USB stick
  - Output of openHAB’s console `shell:info`:

```auto
Karaf
  Karaf version 4.4.4
  Karaf home /openhab/runtime
  Karaf base /openhab/userdata
  OSGi Framework org.eclipse.osgi-3.18.0.v20220516-2155

JVM
  Java Virtual Machine OpenJDK 64-Bit Server VM version 17.0.9+9-Debian-1deb11u1
  Version 17.0.9
  Vendor Debian
  Pid 27
  Uptime 5 days 23 hours
  Process CPU time 1 hour 24 minutes
  Process CPU load 0.00
  System CPU load 0.04
  Open file descriptors 230
  Max file descriptors 1,048,576
  Total compile time 14 minutes
Threads
  Live threads 193
  Daemon threads 112
  Peak 204
  Total started 256941
Memory
  Current heap size 306,941 kbytes
  Maximum heap size 972,800 kbytes
  Committed heap size 481,280 kbytes
  Pending objects 0
  Garbage collector Name = 'G1 Young Generation', Collections = 465, Time = 12.390 seconds
  Garbage collector Name = 'G1 Old Generation', Collections = 0, Time = 0.000 seconds
Classes
  Current classes loaded 34,110
  Total classes loaded 43,396
  Total classes unloaded 9,286
Operating system
  Name Linux version 6.1.21-v8+
  Architecture aarch64
  Processors 4
  Total physical memory 3,885,396 kbytes
  Free physical memory 41,056 kbytes

```

Dear community,

I recently noticed that my Raspi reached its memory (i. e. RAM) limits and I wanted to know which apps consume the most.  
I have several smaller apps that I developed myself and therefore I’m aware of their memory implications. However, openHAB’s memory footprint surprises me a bit - but of course, since I’m not familiar with the codebase, this is not a complaint 😉

Here’s a `htop` screenshot of my system:

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/a/b/ab37dbde0a194950815377ca6a440f1ba4ca4db2.jpeg)

As you can see, openHAB takes 1 GB. What I also noticed is that when changing the `htop` view so that threads are displayed rather than processes, there are approx. 100 threads related to openHAB. This is probably due to the following setting that I had to set within `/opt/openhab/conf/services/runtime.cfg` to get rid of openHAB’s startup error `Error while connecting: Insufficient configured threads: required=11 < max=10 for QueuedThreadPool[OH-httpClient-nz-deconz-72aca4f3f1]@756c419e{STARTED,5<=5<=10,i=1,r=-1,q=0}[ReservedThreadExecutor@552afaf8{reserved=0/1,pending=0}] `:

```auto
org.openhab.webclient:minThreadsShared = 10
org.openhab.webclient:maxThreadsShared = 120
org.openhab.webclient:minThreadsCustom = 10
org.openhab.webclient:maxThreadsCustom = 120

```

After searching a bit in this forum, I found several threads about memory problems, etc. This left me a bit unsure whether I should try to reduce openHAB’s memory usage on my current Raspi or instead buy another Raspi 4 with 8 GB RAM 🤷🏻‍♂️

What am I using openHAB for?

- Capture temperature data from 8 sensors via ZigBee
- Control three LED lights via ZigBee

So here are my questions:

1. Taking the above information into account, does 1 GB of memory seem like a reasonable high memory usage for you?
2. Is there any way to reduce the number of threads without facing the aforementioned startup problem?
3. Is it worth tuning openHAB’s memory usage (e. g. via JVM parameters) or would you rather recommend upgrading my Raspi to 8 GB?

Best regards and thx!

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [May 5, 2024, 4:57pm UTC](https://community.openhab.org/t/memory-usage-of-oh4-on-rpi-4-model-b-within-docker/155802/2 "2024-05-05T16:57:43Z")

</div>

1. No, that’s pretty typical on a 64-bit OH instance running in a container.

2. I doubt it. OH is designed as an event driven multi threaded system.

3. I recommend either:

- don’t use Docker which does add some additional memory requirements
- use 32-bit which has smaller memory requirements
- moving to a machine with me RAM.

There is a new binding on the marketplace that will tell you in the logs if it looks like you’ve more heap allocated than you really need. That can reduce how much RAM OH grabs and holds onto.

The way Java works is it grabs a certain amount of memory when it starts. It doesn’t free that memory and give it back to the OS even if it’s not being used. However, when the max heap size is exceeded, you’ll get OutOfMemory exceptions in the log. _This_ is an infusion that OH has a memory leak it a memory problem. Java manages it’s RAM usage within the heap.

You can change the minimum and maximum heap sizes by passing environment “JAVA\_EXTRA\_OPT= -Xms value.  
-Xmx value” where “value” is replaced with the min and max heap size desired respectively.

But in general, 800 MB to 1.2 GB is pretty typical OH memory usage. OH is built to manage a while lot more than you are doing with it so it’s going to seem like it’s a lot. But if you had dozens to hundreds of devices, you’d find the memory requirements works remain roughly the same.

---

<div class="post-metadata">

**Author:** ![mu88](https://community.openhab.org/user_avatar/community.openhab.org/mu88/32/102048_2.png) [@mu88](https://community.openhab.org/u/mu88)\
**Post date:** [May 5, 2024, 7:37pm UTC](https://community.openhab.org/t/memory-usage-of-oh4-on-rpi-4-model-b-within-docker/155802/3 "2024-05-05T19:37:02Z")

</div>

Thank you very much for your in-depth explanation 💪🏻 is it possible to run a 32 bit Docker image of openHAB on the 64 bit version of Raspberry Pi OS, is there a specific tag? Or would I have to “downgrade” the OS to 32 bit?

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [May 5, 2024, 9:05pm UTC](https://community.openhab.org/t/memory-usage-of-oh4-on-rpi-4-model-b-within-docker/155802/4 "2024-05-05T21:05:05Z")

</div>

I don’t know. What really matters is that it’s the 32-bit version of Java running more than anything. If there is a version of the image that provides that it should work.
