我很好奇为什么在使用ab
, -c 7
(7 个并发线程)对 Python Web 服务器 CherryPy 进行基准测试时,它可以提供 1500 个请求/秒(大约是我所期望的),但是当我更改为-c 8
它时,它会下降到 25 个请求/秒。我在具有四个运行 Python 2.6 的内核的 64 位 Windows 机器上运行 numthreads=10 的 CherryPy(但如果我使用 numthreads=8 或 20 并没有什么不同)。
我半怀疑 Python GIL 是问题的一部分,但我不知道为什么它只在我达到 8 个并发请求线程时才会发生。在四核机器上,我希望它可能会更改为-c 4
,但事实并非如此。
我正在使用web.py附带的单文件 CherryPy Web 服务器,这是我正在测试的 WSGI 应用程序:
from web.wsgiserver import CherryPyWSGIServer
def application(environ, start_response):
start_response("200 OK", [("Content-type", "text/plain")])
return ["Hello World!",]
server = CherryPyWSGIServer(('0.0.0.0', 80), application, numthreads=10)
try:
server.start()
except KeyboardInterrupt:
server.stop()
7 个和 8 个并发线程的ab
输出是:
C:\\> ab -n 1000 -c 7 http://localhost/
...
Concurrency Level: 7
Time taken for tests: 0.670 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 130000 bytes
HTML transferred: 12000 bytes
Requests per second: 1492.39 [#/sec] (mean)
Time per request: 4.690 [ms] (mean)
Time per request: 0.670 [ms] (mean, across all concurrent requests)
Transfer rate: 189.46 [Kbytes/sec] received
C:\\> ab -n 1000 -c 8 http://localhost/
...
Concurrency Level: 8
Time taken for tests: 7.169 seconds
Complete requests: 158
Failed requests: 0
Write errors: 0
Total transferred: 20540 bytes
HTML transferred: 1896 bytes
Requests per second: 22.04 [#/sec] (mean)
Time per request: 362.973 [ms] (mean)
Time per request: 45.372 [ms] (mean, across all concurrent requests)
Transfer rate: 2.80 [Kbytes/sec] received