简体   繁体   中英

CherryPy performance tuning

CherryPy consumes about 15-20% CPU on a single-core Raspberry Pi 1st generation when idle, ie no requests being processed at all. To reduce this, I tried various configuration adjustments, but to no avail. How can I reduce this?

>>> import cherrypy
>>> cherrypy.quickstart()
[29/Apr/2021:14:14:22] ENGINE Listening for SIGTERM.
[29/Apr/2021:14:14:22] ENGINE Listening for SIGHUP.
[29/Apr/2021:14:14:22] ENGINE Listening for SIGUSR1.
[29/Apr/2021:14:14:22] ENGINE Bus STARTING
[29/Apr/2021:14:14:22] ENGINE Started monitor thread 'Autoreloader'.
[29/Apr/2021:14:14:23] ENGINE Serving on http://127.0.0.1
[29/Apr/2021:14:14:23] ENGINE Bus STARTED

top output:

Tasks:  85 total,   1 running,  84 sleeping,   0 stopped,   0 zombie
%Cpu(s): 23.9 us,  8.9 sy,  0.0 ni, 66.6 id,  0.0 wa,  0.0 hi,  0.7 si,  0.0 st
MiB Mem :    430.1 total,    152.9 free,     76.2 used,    201.0 buff/cache
MiB Swap:    100.0 total,    100.0 free,      0.0 used.    297.3 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                                                                                             
10674 root      20   0  131484  21240   8188 S  18.5   4.8   0:45.63 python3                                                                                             
                                                                     

The reason for the high idle CPU usage appears to be an internal connection manager loop, within the cheroot HTTP server, used in CherryPy . The loop contains a command to wait for and select the next connection, but it is given a timeout of 0.01 seconds , which means the loop iterates up to 100 times every second, contributing significantly to idle CPU usage. For more details, see the following issue on GitHub: https://github.com/cherrypy/cheroot/issues/378

This timeout was once at 0.5 seconds , then, to work around connection delay issues introduced with other changes, lowered to 0.01 seconds. In the meantime this is not be required anymore, but only on Windows for unknown reasons Python seems to behave differently and cause new connections to have an additional delay up to this timeout. For more details, see the following pull request, which would align the timeout with a connection expiration interval, defaulting to 0.5 seconds: https://github.com/cherrypy/cheroot/pull/352

The reason for this, in first view bugged, behaviour of Python on Windows still needs to be investigated and in case reported to the Python bug tracker. Any help is highly appreciated, to make CherryPy (respectively cheroot) again a good option on low profile hardware like Raspberry Pi 1, Zero and similar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM