What are the available commands to check what processes are using up from the 1GB RAM memory?
We are quite on the edge with the memory our application and we are starting to wonder how we can make it use less.
Hello there, here are a few commands I’ve used in the past to check memory usage, all of them should be run in the hostOS:
cat /proc/meminfoto get an overview of used memory
top, then press
shift-mto order by memory usage (VSZ). This allows you to see process usage
A couple other commands that I think are very useful:
balena run --rm -it -v /var/run/balena-engine.sock:/var/run/docker.sock:ro wrboyce/utils:ctop: this one will show you usage by container
balena run --rm -it --pid=host wrboyce/utils:htop: like top but nicer
Note this last two commands will pull additional docker images (source code here) from dockerhub. While they are fairly small (about 10MB) this might not be acceptable if your device is on a 4G connection or short on space. Be sure to take this into consideration and remove the containers once you are done if needed.
Thanks for the answer.
wrboyce/utils:ctop:we got this:
but in the Dashboard this is what it is shown:
What is occupying the most of the space? balenaOS ?
Hello, Could you please post the output of htop too (from the host os)?
From that, It looks like balenaEngine (balenad) is consuming the largest portion of memory. However, you may want to order the results by MEM%, to see all the high-memory processes (currently results are ordered by CPU%)
Here it comes the results ordered by MEM% usage.
What do you recommend for freeing up some memory in this situation?
Glancing at the various screenshots you have provided, I see multiple Chromium processes, MySQL, Redis, Node, Fluent, Gunicorn, PiGPIO, and a few more services running. Assuming they are all needed, I am not entirely sure you can lower your memory all that much, you are in the 500 to 700 mb range, which sounds about right (if not actually quite frugal already) for everything you have running. Further memory reductions may not come from killing services, but rather, from optimizing your code / applications. Hope that helps, thanks.
We should not be running multiple instances of mysqld or chromium. Normal “top” does not show all these “duplicate” processes, although this htop provided by tmigone does. But even balenad shows up like 20+ times when running that one. (Typing “H” hides those duplicates, like in the last screenshot.) Is this a concern?
Pushes seems to hang (somewhat sporadically) for us after a while. We have a vague idea that this is related to memory usage, simply because it seems to work consistently when the device has more memory available. (We’ve been reading the memory usage from the dashboard, which does not seem to fully agree with top/htop.) We just re-flashed the device and pushed the same code to it, and it does not use the same amount of memory now. Plus, pushes has worked well this far.
There is one mention though. This device that we are using to push constantly is running in local mode. Maybe it is important, maybe it is not.
Hi there – one thing we should clarifiy is that htop behaves a bit differently from top, in that it shows user threads by default. The H key toggles the display of threads. You can read a bit more about the difference between processes and threads here, but the output you describe sounds correct – multithreaded applications are not at all uncommon.
It’s possible that you may see some difference in memory usage in local mode, but I would not expect this to be signficant.
Given the avenues you’ve investigated already, it does seem likely that code or application optimizations would be your best best, as my colleague recommended.
How did you get
htop installed in the Host OS?
Check Tomas’ guide at the beginning of this thread, he goes into how to run
htop in the host’s PID namespace with some pretty good detail.