Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi Zero WH maxes out at 100% constantly #46

Open
mattanorak opened this issue Nov 4, 2021 · 32 comments
Open

Raspberry Pi Zero WH maxes out at 100% constantly #46

mattanorak opened this issue Nov 4, 2021 · 32 comments
Labels
help wanted Extra attention is needed

Comments

@mattanorak
Copy link

Looking in the dashboard, I see that my RPi Zero WH is constantly maxing out at 99-100% CPU and the effective FPS is anywhere from about 2.2 to 2.22 - consequently the refresh on the screen (when text scrolls) is very slow and jumpy rather than smooth as with the Pi3. I also notice that the clock at the bottom sometimes misses a second or catches up after a pause (especially at the time when scrolling begins on the 'calling at' stations).

It could well be that the Pi Zero WH is just not powerful enough for this, but wanted to raise it in case it's something else causing an issue with this device.

This is only for the Pi Zero WH - the Pi3 is fine.

@chrisys
Copy link
Owner

chrisys commented Nov 5, 2021

This is something that's bugged me for a long time, and I have had a few different debugging sessions with no real improvement. I did the original development work on a Pi 3 and like you found it to be a lot smoother, but had to sacrifice the performance for the convenient form factor of the Zero. However with the recent release of the Zero 2 I am hoping we can have the best of both worlds! I have one arriving in a few days and will put it to work in my sign when I get a chance.

@chrisys chrisys added the help wanted Extra attention is needed label Nov 5, 2021
@mattanorak
Copy link
Author

I've got one coming next week as well. What device would it be under in Balena Cloud?

@LeePorte
Copy link

LeePorte commented Nov 7, 2021

I have a zero 2 and am seeing 78 - 82% CPU utilisation. I'm running the python code directly as it doesn't seem to be supported under Balena Cloud as yet.

@chrisys
Copy link
Owner

chrisys commented Nov 9, 2021

We're still working on adding the device type to balenaCloud but it shouldn't be too much longer. This is the issue to follow for updates: balena-os/balena-raspberrypi#725

@chrisys
Copy link
Owner

chrisys commented Nov 9, 2021

@LeePorte what effective frame rate does the code report in the logs when you're running on the Zero 2?

@LeePorte
Copy link

LeePorte commented Nov 9, 2021

I've seen highs of 17.91 and lows of 10.86

Nov 08 11:14:52 train-sign python3[2778]: Effective FPS: 10.86
Nov 08 11:14:52 train-sign python3[2778]: Effective FPS: 10.88
Nov 09 08:48:29 train-sign python3[10163]: Effective FPS: 17.9
Nov 09 08:48:29 train-sign python3[10163]: Effective FPS: 17.91

@mattanorak
Copy link
Author

Excellent - might give that a try while I'm waiting for the device type to appear on BalenaCloud (physical device arrived today).

@LeePorte
Copy link

If it would help I can post up the systemd service file.

@mattanorak
Copy link
Author

Exellent - if you can!

@LeePorte
Copy link

Here's my service file to use as a base

[Unit]
Description=Train Sign Service
After=multi-user.target

StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
Type=idle
WorkingDirectory=/home/pi/uk-train-departure-display
Restart=on-failure
RestartSec=5s
Environment="TZ=Europe/London"
Environment="departureStation=<STATION_CODE>"
Environment="refreshTime=120"
Environment="screenRotation=2"
Environment="apiKey=<API_KEY>"
Environment="operatingHours=8-22"
Environment="screenBlankHours=1-6"
Environment="outOfHoursName=<STATION_NAME>"
ExecStart=/usr/bin/python3 src/main.py

[Install]
WantedBy=multi-user.target

@mattanorak
Copy link
Author

Perfect - thank you. I'll give it a go later tonight on the Zero2 and let you know how I get on.

@mattanorak
Copy link
Author

Thanks, @LeePorte - For some reason I couldn't get the service file to work, so instead I edited config.py (I also had to put VERSION in the home directory (I think that was a Path statement thing though - or lack thereof).
What I did was just create a cron entry to run on boot and that did the trick.
Before I could get it to work, I had to do a few things like install the dependencies in the requirements.txt file, but that was easy!
Thanks for the tip!
Currently getting about 19.88 FPS standalone on the Zero2W.

@mattanorak
Copy link
Author

@LeePorte - Odd, I've noticed that this seems to stop running after a while (after 30 mins this morning). I checked using:
ps-ef |grep main
and I didn't see the main.py process running as I normally do, so this seems to have terminated.
I am running the command with:
python3 /home/pi/uk-train-departure-display/src/main.py &
It's running in the cron as an @reboot, so rebooting fixes it - temporarily.

Anyt thoughts on this?

@LeePorte
Copy link

I had seen some network timeouts that caused it to die. Though since using the systemd service file, I've not had that issue as it has restart on failure set.

I used the following to create and enable the systemd service file

sudo vi /lib/systemd/system/train-sign.service 
sudo systemctl daemon-reload 
sudo service train-sign start

What method did you use to try and install it?

@mattanorak
Copy link
Author

mattanorak commented Nov 15, 2021

I seem to remember doing something similar (with nano, though, not vi).
what did you put in train-sign.service?
I copied your system file (but used my settings) - and it didn't do anything.
Maybe I'll give it another go.

@LeePorte
Copy link

Nano is fine, use your editor of choice

The contents of train-sign.service was the following with some of the details adjusted (<STATION_CODE>, <API_KEY> and <STATION_NAME>) to suit my info.

[Unit]
Description=Train Sign Service
After=multi-user.target

StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
Type=idle
WorkingDirectory=/home/pi/uk-train-departure-display
Restart=on-failure
RestartSec=5s
Environment="TZ=Europe/London"
Environment="departureStation=<STATION_CODE>"
Environment="refreshTime=120"
Environment="screenRotation=2"
Environment="apiKey=<API_KEY>"
Environment="operatingHours=8-22"
Environment="screenBlankHours=1-6"
Environment="outOfHoursName=<STATION_NAME>"
ExecStart=/usr/bin/python3 src/main.py

[Install]
WantedBy=multi-user.target

It might we worth checking your python3 path with which python3 and making sure it matches.

@mattanorak
Copy link
Author

mattanorak commented Nov 15, 2021

Yep, I set python3 to run as default and in the script anyway, I call python3 ....
I also found that running it like this will also restart the process (I think) if it terminates:
setsid python3 /home/pi/uk-departure-display/src/main.py < /dev/zero &> /home/pi/log.txt &

Next, if this keeps terminating (which it seems to be OK up to now), I'll try belt and braces in a shell script like this:

!/bin/bash
if [ $(ps aux | grep 'yourscript.py' | grep -v grep | wc -l | tr -s "\n") -eq 0 ]; then /your/path/to/yourscript.py; fi &

Messy, but it looks like it would work :-)

@mattanorak
Copy link
Author

OK, I got it working as a service now. I'll see how long it stays up. The only difference I used here (and that seemed to get it working) was instead of:
After=multi-user.target
I used:
Requires=network.target
and then in the main section I added:
User=pi

Fingers crossed....

@LeePorte
Copy link

@mattanorak How's it been holding up?

@LeePorte
Copy link

Interestingly CPU usage seems to be a little lower under Bullseye

bullseye-cpu

@mattanorak
Copy link
Author

Seems to be OK - stayed up all yesterday and is still there this morning :-)
CPU seems roughly the same as yours.
image

Thanks for the assistance - will keep an eye on it and see how it goes.

@chrisys
Copy link
Owner

chrisys commented Dec 6, 2021

Hey @LeePorte @mattanorak since balena now has support for the Pi Zero 2 I wonder if you guys have given it a try?

@LeePorte
Copy link

LeePorte commented Dec 6, 2021

I confess i have not. I've been working on the dual display. If I get a chance I'll give it a spin in the next few days.

@mattanorak
Copy link
Author

Hi - also not had chance to test. I'll see if I can do that this week. I've got a couple of Zero W 2's now and some spare memory cards, so if I get some time I'll give it a whirl.

@chrisys
Copy link
Owner

chrisys commented Dec 9, 2021

Just a heads up guys, I haven't attached a display to my Zero 2 yet but I did try building the project for the Zero 2 and it fails. The way to get it to work at the moment is to set the default device type for the balenaCloud application to the Zero 1 (as you would have done before), then add a Zero 2 to the Zero 1 application. This way the builders build for the 32 bit architecture of the Zero 1 but it still runs on the Zero 2 (64 bit) as it's backward compatible. I will look into the changes necessary to update the project to make it build for 64 bit architectures.

@chrisys
Copy link
Owner

chrisys commented Dec 10, 2021

Scratch that, it should work now due to the workaround in #56

@chrisys
Copy link
Owner

chrisys commented Jul 7, 2023

@mattanorak what is the performance like now with the latest version?

@LeePorte
Copy link

LeePorte commented Jul 7, 2023

@chrisys I've just updated and it's running much faster. Possibly a bit too fast. Though that may just be me being used to how it was before. I'll try and grab a video.

@mattanorak
Copy link
Author

Must admit I've not tried it in the dashboard for a while, I've been running standalone - I'll plug my spare in and give it a go.

@LeePorte
Copy link

LeePorte commented Jul 8, 2023

Here's a video of it running on a PI zero 2W

And the resulting htop

train-sign-htop

Definitely much lower resource use

@chrisys
Copy link
Owner

chrisys commented Jul 11, 2023

@LeePorte oh wow that's definitely scrolling too fast for me! We might need to close this issue and start a new one for scrolling speed to fast now - whodathinkit!

@LeePorte
Copy link

It's much easier to slow things down though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants