我通过 flup 作为线程 fastcgi 运行 Django,由 lighttpd 提供服务,通过套接字进行通信。
在空载情况下,每个 fastcgi 线程的预期 CPU 使用率是多少?启动时,每个线程会以 3-4% 的 CPU 使用率运行一段时间,然后在几个小时内回落至 0.5% 左右。它不会低于这个水平。
这么高的CPU使用率正常吗?我的代码中是否存在某些错误导致空闲循环需要比应有的处理更多的处理?我预计该进程在完全空闲时不会使用可测量的 CPU。
我没有用 Django 做任何复杂得可笑的事情,绝对没有任何需要扩展处理的事情。我意识到这并不是很多负载,但如果这是我引入的错误,我想修复它。
最佳答案
我在 Slicehost (django 1.1, python 2.6) 和 Dreamhost (django 1.0, python 2.5) 上作为 fastcgi 运行的 django 上看过这个,我可以这样说:
运行 top
命令显示进程使用大量 CPU 启动约 2-3 秒,然后几乎立即降至 0。
启动 django 应用程序后运行 ps aux
命令会显示与您所描述的内容类似的内容,但是这实际上是误导性的。来自 ps 的 Ubuntu 手册页:
CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process. This is not ideal, and it does not conform to the standards that ps otherwise conforms to. CPU usage is unlikely to add up to exactly 100%.
基本上,ps
显示的 %CPU 列实际上是进程运行期间的平均值。您看到的衰减是由于初始峰值很高,随后随着时间的推移平均不活动。
关于python - flup/fastcgi空载情况下的cpu使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1522844/