当前位置: 移动技术网 > IT编程>脚本编程>Python > snaic和tornado的简单性能测试

snaic和tornado的简单性能测试

2019年11月03日  | 移动技术网IT编程  | 我要评论

石油新闻,烟台南山教务网,女子公交车内砍人

操作系统 : centos7.3.1611_x64

python 版本 : 3.6.8

tornado版本:6.0.2

snaic版本:19.9.0

cpu : intel(r) core(tm) i5-2320 cpu @ 3.00ghz 4核

之前一直使用tornado作为http相关python程序的框架,最近查资料发现新出的snaic性能很高,这里在同样硬件条件下使用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

使用snaic实现的简单http服务器代码:

https://github.com/mike-zhang/pyexamples/blob/master/httprelate/httpserver/snaictest1.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)

snaic测试结果:

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

snaic的cps是 4959.29 ,平均响应时间是 6.049 ms

修改并发数后的测试数据如下:

 

 测试结果对比如下:

 

从测试数据来看,snaic的cps比tornado高,平均响应时间方面,snaic也比tornado短。

本文github地址:

https://github.com/mike-zhang/mikeblogessays/blob/master/2019/20191102_snaic和tornado的简单性能测试.rst

欢迎补充

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网