question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. Itย collects links to all the places you might be looking at while hunting down a tough bug.

And, if youโ€™re still stuck at the end, weโ€™re happy to hop on a call to see how we can help out.

High idle CPU usage

See original GitHub issue

โ“ Iโ€™m submitting a โ€ฆ

  • ๐Ÿž bug report
  • ๐Ÿฃ feature request
  • โ“ question about the decisions made in the repository

๐Ÿž Describe the bug. What is the current behavior? The idle CPU load has been significantly increased with #199 and further multiplied with #308. The new connection manager seems to imply a loop which significantly loads the CPU, compared to before. With the second PR, the timeout has been reduced from 0.1 to 0.01, which seems to imply a 10 times increased number of loops and hence a multiplication of the CPU load. Now #311 addressed the regression of #199 in a better way, making the reduced timeout obsolete, as far as I understand. I just tried changing the 0.01 here back to 0.1, basically reverting #308, and indeed the CPU load goes back again to match moreless the state of #199 or even lower.

โ“ What is the motivation / use case for changing the behavior? The absolute CPU load may be small, but especially on smaller SBCs this is quite an issue. So to keep cheroot/CherryPy a great HTTP server for embedded devices, it would be great to reduce idle CPU usage to a minimum. For reference: https://github.com/HTPC-Manager/HTPC-Manager/issues/30

๐Ÿ’ก To Reproduce

Steps to reproduce the behavior:

git clone https://github.com/HTPC-Manager/HTPC-Manager.git
cd HTPC-Manager
git checkout MichaIng-CherryPy
pip3 install -Ur requirements.txt
python3 Htpc.py
# Check CPU usage of that process
pip3 install -U cherrypy
python3 Htpc.py
# Check and compare CPU usage
pip3 install -U 'cheroot==8.0.0'
python3 Htpc.py
# Check and compare CPU usage
pip3 install -U 'cheroot==8.10'
python3 Htpc.py
# Check and compare CPU usage
pip3 install -U 'cheroot==8.4.2'
python3 Htpc.py
# Check and compare CPU usage
pip3 install -U 'cheroot'
# Adjust below path according to Python version
sed -i 's/timeout=0\.01/timeout=0\.1/' /usr/local/lib/python3.9/dist-packages/cheroot/connections.py
python3 Htpc.py
# Check and compare CPU usage

๐Ÿ’ก Expected behavior

I expect a minimal CPU usage when the HTTP server is not accessed at all.

๐Ÿ“‹ Details

No logs, I basically did it via htop -d 10. Not a very precise tool for measuring process CPU usage, but the differences are very significant when counting the seconds in which the CPU time in centiseconds raises.

๐Ÿ“‹ Environment

  • Cheroot version: 8.5.2 and others (see above)
  • CherryPy version: 18.6.1
  • Python version: 3.9.2 and others
  • OS: Debian Bullseye and others
  • Browser: not applicable

๐Ÿ“‹ Additional context

There are no errors involved, just the connection manager itself checking for idle connections (as far as I understood) very often, which implies CPU usage.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
webknjazcommented, Jul 21, 2021

Thatโ€™s alright. Now we wait ๐Ÿ˜ƒ Iโ€™d accept a PR but Iโ€™d like to get more feedback first because previous refactoring attempts caused regressions which Iโ€™d like to avoid (also, Iโ€™m not sure if we can come up with proper regression tests for the CI to catch problems in the future).

0reactions
MichaIngcommented, Jan 3, 2022

This has now been merged here: https://github.com/cherrypy/cheroot/pull/401 Testing/verifying the idle CPU usage benefits would be welcome.

On Windows systems, sadly a capped timeout needs to stay, as the connection handler select() function somehow on Windows does not return as fast as a connection is detected. The timeout however has been increased from 0.01 to 0.05 seconds, which seems to be a good balance between idle CPU usage and max delay for processing an incoming connection. For Raspberry Pi with Linux however this doesnโ€™t play a role since select() returns immediately once incoming connections appear. That expiration_interval (defaulting to 0.5 seconds) needs to be kept as well on Linux is to assure that expired connections are disconnected and removed in time, since new connections and expiry are done within the same loop.

Read more comments on GitHub >

github_iconTop Results From Across the Web

High CPU usage at idle. Win 10 Pro - Microsoft Community
Whenever I check with MSI Afterburner, it says that the CPU usage sits at about 90 percent.
Read more >
System Idle Process High CPU Usage [Solved] - Driver Easy
The high percent of cpu indicates that a large amount of process power is not being used. If it is at 100, 99...
Read more >
Solved: System Idle Process High CPU usage on Windows 10
The System Idle Process is a system process that tells you the percentage of time your CPU is idle. If you see system...
Read more >
Fix: System Idle process is having a high CPU usage
Fix: System Idle process is having a high CPU usage ยท Fix-1 Clean Boot your computer- ยท Fix- 2 Disable Startup processes- ยท...
Read more >
Idle Process High CPU - Driver Support
Idle Process High CPU ยท Windows Can Try to Update the Drivers. Knowing that the O/S doesn't always find the right driver, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found