Several runtime optimizations to reduce CPU load and temperature and increase battery life
Hi, I love this project and also the MupiHAT that you guys have developed. I have two MupiBoxes in operation, each running a Raspberry Pi 3 B+. When I started using your SW, I realized a pretty high CPU load even in idle state and after letting the system settle for a couple of minutes. At least in my case using Raspberry 3's. So, I started profiling and optimizing. I am running these changes successfully on my two boxes over the last couple of months, so it can be considered as tested.?
What did I do:
- Reduce the frequency of the execution of several Mupi services
- Move calls to
jqfrom inside endless loops to outside
What did I achieve:
- approx. 10° lower CPU temperature compared to your version
- higher responsiveness of the Chromium UI due to more available CPU power
- Drive-by improvement: Kernel 6.6 compatibility (Background: Stop using /sys/class/gpio – it’s deprecated)
Disadvantages:
- Some settings will now require a reboot or at least a restart of the affected service to take effect
Further improvements:
- I recommend to migrate
autosetup/autosetup.shandupdate/start_mupibox_update.shinto one script, because they share a lot of copied code and they start to diverge making it a mess to maintain.
When viewing the changes in this PR I recommend disabling whitespaces in view.
When merging this PR I recommend doing a squash merge, because otherwise a lot of commits would be merged onto the main branch.
Nice work and thank you for the contribution. Out of interest: What change did bring the most benefit wrt CPU load?
Nice work and thank you for the contribution. Out of interest: What change did bring the most benefit wrt CPU load?
Thanks! In general, I figured out that jq is causing high load as it seems to be very expensive/unoptimized. So I tried to remove it from inside endless loops at the cost of "online" modifiability of parameters without reboot/restart of the service. Or at least only call jq with some more rare condition instead of anytime the loop is run. So to answer your question, I assume the change in scripts/mupibox/mupi_start_led.sh brought the most significant improvement as I removed 7 calls to jq here.
Also lowering the frequency of execution brought a lot, as in practice these parameters rarely change (imho).
We will test this gradually and implement it if necessary. Please note that we will continue to download the update via our repository.
We will test this gradually and implement it if necessary.
Sure. If you want, I could also split this huge PR into smaller ones for dedicated updates. It would take some time, as I'd need to find some free time for it, though.
Please note that we will continue to download the update via our repository.
Sure. What exactly do you mean with this? I did not expect you to switch to any other repository. 😕