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


硬件环境

Intel Core i5-3230M CPU @ 2.60GHz × 4

内存: 7.4 GiB

操作系统: Ubuntu 14.04 64 位


测试代码(hello.py)

from bottle import Bottle, run

app = Bottle()

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

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


uwsgi

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


结果:

ab -c 100 -n 50000 "http://localhost:8000/hello"
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
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 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8000

Document Path:          /hello
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   3.288 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      4550000 bytes
HTML transferred:       600000 bytes
Requests per second:    15206.71 [#/sec] (mean)
Time per request:       6.576 [ms] (mean)
Time per request:       0.066 [ms] (mean, across all concurrent requests)
Transfer rate:          1351.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.3      2       6
Processing:     1    5   1.3      4      14
Waiting:        1    4   1.7      4      12
Total:          4    7   0.8      6      19
WARNING: The median and mean for the total time are not within a normal deviation
        These results are probably not that reliable.

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

gunicorn

gunicorn -w 2 hello:app


结果:


ab -c 100 -n 50000 "http://localhost:8000/hello"
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
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 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests


Server Software:        gunicorn/19.3.0
Server Hostname:        localhost
Server Port:            8000

Document Path:          /hello
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   8.821 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      8600000 bytes
HTML transferred:       600000 bytes
Requests per second:    5668.37 [#/sec] (mean)
Time per request:       17.642 [ms] (mean)
Time per request:       0.176 [ms] (mean, across all concurrent requests)
Transfer rate:          952.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       7
Processing:     3   18   2.0     17      34
Waiting:        3   17   2.0     17      34
Total:         10   18   2.0     17      36

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     17
  75%     18
  80%     18
  90%     19
  95%     23
  98%     23
  99%     24
 100%     36 (longest request)


总结

方案
并发
最大响应时间(ms)
uwsgi
1520619
gunicorn566836