码迷,mamicode.com
首页 > 其他好文 > 详细

简单性能测试: bottle vs flask

时间:2015-08-06 02:13:10      阅读:1116      评论:0      收藏:0      [点我收藏+]

标签:python bottle flask uwsgi

###目的
测试在不同的部署方式下的性能。


###硬件环境

Intel Core i5-3230M CPU @ 2.60GHz × 4
内存: 7.4 GiB
操作系统: Ubuntu 14.04 64 位

###uwsgi
```
uwsgi_python --http-socket=:8000 --workers=2 --wsgi-file hello.py --callable app 2>/dev/null
```


###bottle测试代码(hello.py)
```
from bottle import Bottle, run

app = Bottle()

@app.route(‘/‘)
def hello():
    return "Hello World!"

if __name__ == "__main__":
    run(app, host=‘localhost‘, port=8000)
```



结果:
```
ab -c 100 -n 20000 "http://localhost:8000/"
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8000

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   1.333 seconds
Complete requests:      20000
Failed requests:        0
Total transferred:      1820000 bytes
HTML transferred:       240000 bytes
Requests per second:    14999.67 [#/sec] (mean)
Time per request:       6.667 [ms] (mean)
Time per request:       0.067 [ms] (mean, across all concurrent requests)
Transfer rate:          1332.98 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.3      3       6
Processing:     1    5   1.2      5       9
Waiting:        1    4   1.5      4       8
Total:          4    7   0.8      7      11

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

###flask测试部署(hello.py)
```
from flask import Flask
app = Flask(__name__)

@app.route(‘/‘)
def hello_world():
    return ‘Hello World!‘

if __name__ == ‘__main__‘:
    app.run()
```

结果:
```
ab -c 100 -n 20000 "http://localhost:8000/"
This is ApacheBench, Version 2.3 <$Revision: 1604373 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 2000 requests
Completed 4000 requests
Completed 6000 requests
Completed 8000 requests
Completed 10000 requests
Completed 12000 requests
Completed 14000 requests
Completed 16000 requests
Completed 18000 requests
Completed 20000 requests
Finished 20000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8000

Document Path:          /
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   3.164 seconds
Complete requests:      20000
Failed requests:        0
Total transferred:      1820000 bytes
HTML transferred:       240000 bytes
Requests per second:    6321.63 [#/sec] (mean)
Time per request:       15.819 [ms] (mean)
Time per request:       0.158 [ms] (mean, across all concurrent requests)
Transfer rate:          561.79 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       6
Processing:     5   16   2.1     15      28
Waiting:        4   16   2.1     15      28
Total:         10   16   2.2     15      32

Percentage of the requests served within a certain time (ms)
  50%     15
  66%     15
  75%     15
  80%     16
  90%     20
  95%     21
  98%     21
  99%     22
 100%     32 (longest request)
```

###总结

|方案|并发|最大响应时间(ms)|
|---|---|---------------|
|bottle|14999|11|
|flask|6321|32|




简单性能测试: bottle vs flask

标签:python bottle flask uwsgi

原文地址:http://517995.blog.51cto.com/507995/1682047

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!