之前看到挺多同学推荐Gunicorn+Gevent来跑Flask的,就在机子上试了一下。一个简单的flask hello world程序,发现gevent似乎没有什么提升,是因为这种测试环境没有凸显异步的优势?
跟http://
rfyiamcool.blog.51cto.com/1030776/1276364 这博文上说的结果有些不同。
用ab -c 100 -n 2000 参数测试
python直接启动gevent测试的负载
----------
Concurrency Level: 100
Time taken for tests: 1.651 seconds
Complete requests: 2000
Failed requests: 186
(Connect: 0, Receive: 0, Length: 186, Exceptions: 0)
Write errors: 0
Total transferred: 285814 bytes
HTML transferred: 25814 bytes
Requests per second: 1211.57 [#/sec] (mean)
Time per request: 82.537 [ms] (mean)
Time per request: 0.825 [ms] (mean, across all concurrent requests)
Transfer rate: 169.08 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 1.8 2 12
Processing: 19 79 27.2 63 127
Waiting: 18 78 27.5 62 127
Total: 24 81 26.5 66 131
Percentage of the requests served within a certain time (ms)
50% 66
66% 84
75% 119
80% 120
90% 122
95% 123
98% 124
99% 124
100% 131 (longest request)
---------
直接用gunicorn启动
----------------
Concurrency Level: 100
Time taken for tests: 1.665 seconds
Complete requests: 2000
Failed requests: 199
(Connect: 0, Receive: 0, Length: 199, Exceptions: 0)
Write errors: 0
Total transferred: 345801 bytes
HTML transferred: 25801 bytes
Requests per second: 1201.11 [#/sec] (mean)
Time per request: 83.256 [ms] (mean)
Time per request: 0.833 [ms] (mean, across all concurrent requests)
Transfer rate: 202.81 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 3.5 1 35
Processing: 7 80 28.5 66 140
Waiting: 7 80 28.4 66 140
Total: 15 82 28.0 67 142
Percentage of the requests served within a certain time (ms)
50% 67
66% 68
75% 85
80% 125
90% 132
95% 138
98% 140
99% 140
100% 142 (longest request)
--------------------
使用gunicorn -k gevent方式启动
---------------------
Concurrency Level: 100
Time taken for tests: 1.939 seconds
Complete requests: 2000
Failed requests: 203
(Connect: 0, Receive: 0, Length: 203, Exceptions: 0)
Write errors: 0
Total transferred: 345797 bytes
HTML transferred: 25797 bytes
Requests per second: 1031.36 [#/sec] (mean)
Time per request: 96.959 [ms] (mean)
Time per request: 0.970 [ms] (mean, across all concurrent requests)
Transfer rate: 174.14 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 4.3 1 43
Processing: 16 94 31.7 79 161
Waiting: 16 93 31.7 79 161
Total: 20 95 31.0 79 165
Percentage of the requests served within a certain time (ms)
50% 79
66% 113
75% 123
80% 123
90% 152
95% 154
98% 155
99% 156
100% 165 (longest request)
--------------------
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.