python2/python3各web框架基准测试

python有python2和python3之分,还有pypy2和pypy3的jit优化版本,web框架有很多,japronto性能甚至远胜nodejs和go,主要原因是它使用c语言实现了事件循环和http解析,tornado比较慢,同时又有4.x和5.x版本之分,5.x版本默认使用python3的asyncio作为异步事件驱动器,而三方的uvloop又据说有更好的性能。总归来说,测试对比再所难免。

siege 'http://10.10.10.x:8888/' -c 30 -t 30s -b

go1.6.2
Transactions:              414819 hits
Availability:              100.00 %
Elapsed time:               29.25 secs
Data transferred:           32.04 MB
Response time:                0.00 secs
Transaction rate:        14181.85 trans/sec
Throughput:                1.10 MB/sec
Concurrency:               29.86
Successful transactions:      414819
Failed transactions:               0
Longest transaction:            0.07
Shortest transaction:            0.00

python-3.5.2 japronto-0.1.1 on uvloop-0.8.1 同步
Transactions:              517834 hits
Availability:              100.00 %
Elapsed time:               29.45 secs
Data transferred:           40.50 MB
Response time:                0.00 secs
Transaction rate:        17583.50 trans/sec
Throughput:                1.38 MB/sec
Concurrency:               29.70
Successful transactions:      517834
Failed transactions:               0
Longest transaction:            0.06
Shortest transaction:            0.00

python-3.5.2 japronto-0.1.1 on uvloop-0.8.1 异步
Transactions:              518110 hits
Availability:              100.00 %
Elapsed time:               29.51 secs
Data transferred:           40.52 MB
Response time:                0.00 secs
Transaction rate:        17557.10 trans/sec
Throughput:                1.37 MB/sec
Concurrency:               29.67
Successful transactions:      518110
Failed transactions:               0
Longest transaction:            0.08
Shortest transaction:            0.00

python-3.5.2 tornado-5.1
Transactions:               36831 hits
Availability:              100.00 %
Elapsed time:               29.47 secs
Data transferred:            2.88 MB
Response time:                0.02 secs
Transaction rate:         1249.78 trans/sec
Throughput:                0.10 MB/sec
Concurrency:               29.97
Successful transactions:       36831
Failed transactions:               0
Longest transaction:            0.40
Shortest transaction:            0.00

python-2.7.12 tornado-5.1
Transactions:               37760 hits
Availability:              100.00 %
Elapsed time:               29.29 secs
Data transferred:            2.95 MB
Response time:                0.02 secs
Transaction rate:         1289.18 trans/sec
Throughput:                0.10 MB/sec
Concurrency:               29.98
Successful transactions:       37760
Failed transactions:               0
Longest transaction:            0.38
Shortest transaction:            0.01

python-3.5.2 tornado-5.1 on uvloop-0.8.1
Transactions:               40683 hits
Availability:              100.00 %
Elapsed time:               29.16 secs
Data transferred:            3.18 MB
Response time:                0.02 secs
Transaction rate:         1395.16 trans/sec
Throughput:                0.11 MB/sec
Concurrency:               29.97
Successful transactions:       40683
Failed transactions:               0
Longest transaction:            0.36
Shortest transaction:            0.00

python-2.7.12 tornado-4.5.3
Transactions:               45485 hits
Availability:              100.00 %
Elapsed time:               29.43 secs
Data transferred:            3.56 MB
Response time:                0.02 secs
Transaction rate:         1545.53 trans/sec
Throughput:                0.12 MB/sec
Concurrency:               29.97
Successful transactions:       45485
Failed transactions:               0
Longest transaction:            0.17
Shortest transaction:            0.00

python-3.5.2 tornado-4.5.3
Transactions:               46496 hits
Availability:              100.00 %
Elapsed time:               29.95 secs
Data transferred:            3.64 MB
Response time:                0.02 secs
Transaction rate:         1552.45 trans/sec
Throughput:                0.12 MB/sec
Concurrency:               29.97
Successful transactions:       46496
Failed transactions:               0
Longest transaction:            0.17
Shortest transaction:            0.00

pypy5.1.2(Python 2.7.10)  tornado-4.5.3
Transactions:              159270 hits
Availability:              100.00 %
Elapsed time:               29.58 secs
Data transferred:           12.46 MB
Response time:                0.01 secs
Transaction rate:         5384.38 trans/sec
Throughput:                0.42 MB/sec
Concurrency:               29.92
Successful transactions:      159270
Failed transactions:               0
Longest transaction:            0.05
Shortest transaction:            0.00

测试代码很简单,就是请求后,返回一个很简单的json对象。总体来说,python2和python3性能相差不大,pypy3则有近4倍的提升。japronto确实很快,比go略快,比运行于CPython上的tornado快10倍。uvloop确实有一定性能提升,使用也简单。tornado的5.x版本比4.x版本慢不少。

大体看来:pypy3 tornado-4.5.3 是不错选择,但使用了so的模块,改动量还是非常大的。

发表于2018-07-26 17:47   修改于2018-07-26 17:47   评论:0   阅读:273  



回到顶部

首页 | 关于我 | 关于本站 | 站内留言 | rss
python logo   django logo