Bug 433796

Summary: kio_http_cache_cleaner is busy waiting
Product: [Frameworks and Libraries] frameworks-kio Reporter: Harald Sitter <sitter>
Component: HTTPAssignee: KIO Bugs <kio-bugs-null>
Status: REPORTED ---    
Severity: normal CC: kdelibs-bugs-null, nate, oliverst
Priority: NOR    
Version First Reported In: git master   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Harald Sitter 2021-03-01 15:51:50 UTC
SUMMARY
(this is very poorly researched, but if I don't write it down I'll forget tomorrow)

kio_http_cache_cleaner has a loop that is basically always true and inside it waits for 100ms and then either talks to sockets (on the other end I guess is the http.so) or not. it wraps around and the dance continues.
This effectively is causing entirely pointless CPU load. Not that big a deal on desktops but in the >0.5% range on plasma mobile. Always. Even when idle. My poor battery :(

STEPS TO REPRODUCE
1. run the cleaner

OBSERVED RESULT
watch it doing stuff when there is nothing to do (at least I think there isn't)

EXPECTED RESULT
be completely idle unless there's work to be done

ADDITIONAL INFORMATION
This actually was made worse in a change a while ago that reduced the sleep time from 1s to 100ms because the cleaner wasn't shutting down properly. That did make me wonder why it is busy looping at all though. The application can simply run an eventloop and attach to QLocalServer::newConnection (which I presume will not busy wait) thereby being able to exit somewhat immediately and having zero need for any amount of while(true){} looping.
Comment 1 Oliver Stoeneberg 2023-02-10 23:59:50 UTC
I see something similar with 5.102 on Manjaro Linux with Plasma Mobile.

When the system is idle and no applications are open kio_http_cache_cleaner is constantly in the top 3 in powertop with an Usage of about 0,9 ms/s and Events/s of 9,8.

Terminating the process with SIGTERM doesn't show much of an improvement overall in consumption and CPU load but it still seems quite unnecessary.