python常用web框架简单性能测试结果分享(包含django、flask、bottle、tornado)
测了一下django、flask、bottle、tornado框架本身最简单的性能。对django的性能完全无语了。
django、flask、bottle均使用gunicorn+gevent启动,单进程,并且关闭DEBUG,请求均只返回一个字符串ok。
tornado直接自己启动,其他内容一致。
测试软件为siege,测试os为cenos664位,测试命令为:
siege-c100-r100-bhttp://127.0.0.1:5000/
django测试结果为:
Transactions: 10000hits Availability: 100.00% Elapsedtime: 18.51secs Datatransferred: 0.02MB Responsetime: 0.18secs Transactionrate: 540.25trans/sec Throughput: 0.00MB/sec Concurrency: 99.35 Successfultransactions: 10000 Failedtransactions: 0 Longesttransaction: 0.30 Shortesttransaction: 0.12
django(去掉所有middleware)测试结果为:
Transactions: 10000hits Availability: 100.00% Elapsedtime: 12.97secs Datatransferred: 0.02MB Responsetime: 0.13secs Transactionrate: 771.01trans/sec Throughput: 0.00MB/sec Concurrency: 99.41 Successfultransactions: 10000 Failedtransactions: 0 Longesttransaction: 0.28 Shortesttransaction: 0.12
flask测试结果为:
Transactions: 10000hits Availability: 100.00% Elapsedtime: 5.47secs Datatransferred: 0.02MB Responsetime: 0.05secs Transactionrate: 1828.15trans/sec Throughput: 0.00MB/sec Concurrency: 96.25 Successfultransactions: 10000 Failedtransactions: 0 Longesttransaction: 0.11 Shortesttransaction: 0.00
bottle测试结果为:
Transactions: 10000hits Availability: 100.00% Elapsedtime: 4.55secs Datatransferred: 0.02MB Responsetime: 0.04secs Transactionrate: 2197.80trans/sec Throughput: 0.00MB/sec Concurrency: 96.81 Successfultransactions: 10000 Failedtransactions: 0 Longesttransaction: 0.09 Shortesttransaction: 0.00
tornado测试结果为:
Transactions: 10000hits Availability: 100.00% Elapsedtime: 7.06secs Datatransferred: 0.02MB Responsetime: 0.07secs Transactionrate: 1416.43trans/sec Throughput: 0.00MB/sec Concurrency: 99.51 Successfultransactions: 10000 Failedtransactions: 0 Longesttransaction: 0.09 Shortesttransaction: 0.01
可见纯框架自身的性能为:
bottle>flask>tornado>django
结合实际使用:
tornado使用了异步驱动,所以在写业务代码时如果稍有同步耗时性能就会急剧下降;
bottle需要自己实现的东西太多,加上之后不知道性能会怎样;
flask性能稍微差点,但周边的支持已经很丰富了;
django就不说了,性能已经没法看了,唯一的好处就是开发的架子都已经搭好,开发速度快很多
因为最近正在为一个项目选型发愁,所以就测了一下,记录在此吧。
PS:2014-6-23使用centos664位重新进行了测试,得出与生产环境更匹配的结果,并修改了文章。