sanic和tornado的簡單性能測試


操作系統 : CentOS7.3.1611_x64

Python 版本 : 3.6.8

tornado版本:6.0.2

sanic版本:19.9.0

CPU : Intel(R) Core(TM) i5-2320 CPU @ 3.00GHz 4核

之前一直使用tornado作為http相關python程序的框架,最近查資料發現新出的sanic性能很高,這里在同樣硬件條件下使用ab進行簡單的壓測。

准備工作

安裝apache ab工具:

yum -y install httpd-tools

壓測命令:

ab -c 30 -n 100000 http://127.0.0.1:9093/

參數說明:

-c :模擬並發數

-n : 總請求數

對比測試

使用tornado實現的簡單http服務器代碼:

https://github.com/mike-zhang/pyExamples/blob/master/httpRelate/httpServer/tornadoTest1.py

使用sanic實現的簡單http服務器代碼:

https://github.com/mike-zhang/pyExamples/blob/master/httpRelate/httpServer/sanicTest1.py

tornado測試結果:

Server Software:        TornadoServer/6.0.2
Server Hostname:        127.0.0.1
Server Port:            9093

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      30
Time taken for tests:   82.282 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      20700000 bytes
HTML transferred:       1200000 bytes
Requests per second:    1215.33 [#/sec] (mean)
Time per request:       24.685 [ms] (mean)
Time per request:       0.823 [ms] (mean, across all concurrent requests)
Transfer rate:          245.68 [Kbytes/sec] received

Connection Times (ms)
                          min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       8
Processing:     1   25  10.3     25      74
Waiting:        1   24  10.3     25      74
Total:          1   25  10.3     25      74

Percentage of the requests served within a certain time (ms)
  50%     25
  66%     30
  75%     33
  80%     34
  90%     37
  95%     39
  98%     41
  99%     42
 100%     74 (longest request)

sanic測試結果:

Server Software:
Server Hostname:        127.0.0.1
Server Port:            9093

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      30
Time taken for tests:   20.164 seconds
Complete requests:      100000
Failed requests:        0
Write errors:           0
Total transferred:      11100000 bytes
HTML transferred:       1200000 bytes
Requests per second:    4959.29 [#/sec] (mean)
Time per request:       6.049 [ms] (mean)
Time per request:       0.202 [ms] (mean, across all concurrent requests)
Transfer rate:          537.58 [Kbytes/sec] received

Connection Times (ms)
                          min  mean[+/-sd] median   max
Connect:        0    2   0.5      2      11
Processing:     1    4   1.5      4      38
Waiting:        0    4   1.4      3      37
Total:          1    6   1.5      6      41

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      6
  75%      7
  80%      7
  90%      7
  95%      8
  98%      9
  99%     10
 100%     41 (longest request)

從測試結果可以看到,開啟兩個進程情況下:

tornado的cps是 1215.33 ,平均響應時間是 24.685 ms

sanic的cps是 4959.29 ,平均響應時間是 6.049 ms

修改並發數后的測試數據如下:

 

 測試結果對比如下:

 

從測試數據來看,sanic的cps比tornado高,平均響應時間方面,sanic也比tornado短。

本文github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2019/20191102_sanic和tornado的簡單性能測試.rst

歡迎補充


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM