Josar / RandomStuff

8 stars 6 forks source link

Raspberry Pi resource hog (110% CPU on Pi 3 B+) #2

Closed y8s closed 5 years ago

y8s commented 5 years ago

RFmqtt works incredibly well on my HomeAssistant (and formerly OpenHAB) pi but I've noticed it's using more than its fair share of CPU time.

I've seen other people suggest that RFsniffer had this problem as well and they added a sleep or wait to reduce the load by a factor of ten.

I frequently preface all of my GitHub comments with "I'm not a programmer..." but I'm going to try to take a stab at adding some idle time and still receiving data.

Reference link: https://github.com/ninjablocks/433Utils/issues/16

y8s commented 5 years ago

Similar to the original issue above, I added a usleep(5000); before the closing bracket of the second while loop and the CPU% is down to around the single digits. I'll do some testing to see if it receives everything properly.

Josar commented 5 years ago

@y8s nanosleep might be a letter choice. As there are rumors of depracation for usleep.

http://man7.org/linux/man-pages/man2/nanosleep.2.html

I will have a look when i find some time. Thanks for the hint.

irosaurus commented 5 years ago

@y8s Your hint was great. Using usleep(5000); helped me to reduce the CPU usage from 100% down to 2-3%!

@Josar Definitely worth to implement it. Besides that, really appreciate your efforts in providing this nice littl tool!

Cheers

Josar commented 5 years ago

I included 2 sleep functions as test, this reduces CPU load. But when keeping the sender pressed it seems CPU loads stays lower then when waiting for the next RF frame to be received. Thus, there are still some questions.