簡體   English   中英

與7個請求線程相比,CherryPy 60x的基准測試速度較慢

[英]CherryPy 60x as slow in benchmark with 8 requesting threads compared to 7

我很好奇為什么在使用ab對Python Web服務器CherryPy進行基准測試時,使用-c 7 (7個並發線程)它可以服務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

在我的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.000089

最初的“GET”數據包也沒有被Wireshark接收。 出於某種原因, ab嘗試發送請求並失敗,即使TCP連接是雙ACk就好了。 然后,客戶端的TCP堆棧等待幾秒鍾,以便從未發送過ACK的數據包,當它看不到ACK時,重試並成功。

就個人而言,我不擔心。 如果有問題,那就不是CherryPy的問題了。 它可能與ab的內部相關,使用HTTP / 1.0而不是1.1,缺少keepalive,使用localhost而不是真正的socket(模擬網絡流量的某些現實而忽略其他),使用Windows(wink),同一界面上的其他流量,加載到CPU上......列表一直在繼續。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM