我很好奇为什么在使用ab和-c 7 (7个并发线程)测试Python web服务器CherryPy时,它可以处理1500个请求/秒(和我预期的差不多),但当我改用-c 8时,它会降到25个请求/秒。我在64位Windows机器上运行CherryPy和numthreads=10 (但如果我使用numthreads=8或20也没什么不同),它有四个运行Python2.6内核的Windows机器。
我怀疑Python GIL是问题的一部分,但我不知道为什么只有当我获得多达8个并发请求线程时才会发生这种情况。在一台四核的机器上,我预计它可能会在-c 4上发生变化,但事实并非如此。
我使用的是web.py附带的单文件WSGI服务器,下面是我正在测试的CherryPy应用程序:
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发布于 2011-02-15 04:59:27
在我的linux机器上,这是由于来自ab的TCP数据包的重新传输,尽管我不能确切地确定原因:
No. Time Source Destination Protocol Info Delta
10682 21.218156 127.0.0.1 127.0.0.1 TCP http-alt > 57246 [SYN, ACK] Seq=0 Ack=0 Win=32768 Len=0 MSS=16396 TSV=17307504 TSER=17306704 WS=6 21.218156
10683 21.218205 127.0.0.1 127.0.0.1 TCP 57246 > http-alt [ACK] Seq=82 Ack=1 Win=513 Len=0 TSV=17307504 TSER=17307504 SLE=0 SRE=1 0.000049
10701 29.306438 127.0.0.1 127.0.0.1 HTTP [TCP Retransmission] GET / HTTP/1.0 8.088233
10703 29.306536 127.0.0.1 127.0.0.1 TCP http-alt > 57246 [ACK] Seq=1 Ack=82 Win=512 Len=0 TSV=17309526 TSER=17309526 0.000098
10704 29.308555 127.0.0.1 127.0.0.1 TCP [TCP segment of a reassembled PDU] 0.002019
10705 29.308628 127.0.0.1 127.0.0.1 TCP 57246 > http-alt [ACK] Seq=82 Ack=107 Win=513 Len=0 TSV=17309526 TSER=17309526 0.000073
10707 29.309718 127.0.0.1 127.0.0.1 TCP [TCP segment of a reassembled PDU] 0.001090
10708 29.309754 127.0.0.1 127.0.0.1 TCP 57246 > http-alt [ACK] Seq=82 Ack=119 Win=513 Len=0 TSV=17309526 TSER=17309526 0.000036
10710 29.309992 127.0.0.1 127.0.0.1 HTTP HTTP/1.1 200 OK (text/plain) 0.000238
10711 29.310572 127.0.0.1 127.0.0.1 TCP 57246 > http-alt [FIN, ACK] Seq=82 Ack=120 Win=513 Len=0 TSV=17309527 TSER=17309526 0.000580
10712 29.310661 127.0.0.1 127.0.0.1 TCP http-alt > 57246 [ACK] Seq=120 Ack=83 Win=512 Len=0 TSV=17309527 TSER=17309527 0.000089Wireshark也没有接收到原始的"GET“数据包。由于某些原因,ab尝试发送请求但失败了,即使TCP连接是双重确认的也没有问题。然后,客户端的TCP堆栈等待几秒钟,等待从未发送的数据包得到ACK,当它没有看到ACK时,重试并成功。
就我个人而言,我不会担心这件事。如果有问题,那也不是CherryPy的问题。这可能与ab的内部结构有关,使用HTTP/1.0而不是1.1,缺少keepalive,使用本地主机而不是真正的套接字(模拟网络流量的一些实际情况并忽略其他流量),使用Window(眨眼),同一接口上的其他流量,CPU...the列表上的负载等等。
https://stackoverflow.com/questions/4993526
复制相似问题