webpy/flask/bottle性能测试
这三个都是Python WSGI的web开发框架,到底用哪个呢?单纯从性能的角度而言,可能哪个快就用哪个,但是这也不是绝对的。比如我就比较喜欢webpy的router配置放在一个文件中,而flask和bottle的配置分散到各个文件中,从开发角度,写在哪里无所谓,但是从阅读的角度,webpy就比较方便了。因为在工作中本着拿来主义的角度使用了webpy,但是看起来flask也很火,而bottle据说更是一个精简的文件,所以本文简单测试了三者的性能,供参考。
测试方法:用三者分别写一个URL API,这个API直接返回“hello world!”字符串,用uwsgi启动python应用。客户端采用apache benchmark工具:ab,对server执行500000次请求,并发为1000,然后比较ab的测试结果,同时用统计机器的CPU消耗。
测试脚本:http://pan.baidu.com/s/1URGJ0,提取密码:6thp
测试结果:
CPU曲线图(测试顺序:webpy,sleep 120秒,flask,sleep 120秒,bottle)
ab的测试结果:
- webpy
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
……
Completed 50000 requests
Completed …… requests
Finished 500000 requests
……
Server Port: 8010
Document Path: /
Document Length: 12 bytes Concurrency Level: 1000
Time taken for tests: 1533.489 seconds
Complete requests: 500000
Failed requests: 24246
(Connect: 0, Receive: 0, Length: 24246, Exceptions: 0)
Write errors: 0
Total transferred: 14748374 bytes
HTML transferred: 5709048 bytes
Requests per second: 326.05 [#/sec] (mean)
Time per request: 3066.978 [ms] (mean)
Time per request: 3.067 [ms] (mean, across all concurrent requests)
Transfer rate: 9.39 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 10.1 1 3000
Processing: 111 2962 7581.0 645 69933
Waiting: 0 1629 3949.2 642 68942
Total: 218 2963 7581.6 646 69933 Percentage of the requests served within a certain time (ms)
50% 646
......
100% 69933 (longest request)
- flask
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
......
Completed 50000 requests
......
Completed 500000 requests
Finished 500000 requests
......
Server Port: 8020 Document Path: /
Document Length: 12 bytes Concurrency Level: 1000
Time taken for tests: 862.997 seconds
Complete requests: 500000
Failed requests: 17067
(Connect: 0, Receive: 0, Length: 17067, Exceptions: 0)
Write errors: 0
Total transferred: 43946903 bytes
HTML transferred: 5795196 bytes
Requests per second: 579.38 [#/sec] (mean)
Time per request: 1725.993 [ms] (mean)
Time per request: 1.726 [ms] (mean, across all concurrent requests)
Transfer rate: 49.73 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 42.4 1 3002
Processing: 40 1635 6311.8 196 69819
Waiting: 0 725 3301.8 195 69030
Total: 71 1636 6312.6 197 69819 Percentage of the requests served within a certain time (ms)
50% 197
......
100% 69819 (longest request)
- bottle
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
......
Completed 50000 requests
......
Completed 500000 requests
Finished 500000 requests
......
Server Port: 8030 Document Path: /
Document Length: 12 bytes Concurrency Level: 1000
Time taken for tests: 419.576 seconds
Complete requests: 500000
Failed requests: 4111
(Connect: 0, Receive: 0, Length: 4111, Exceptions: 0)
Write errors: 0
Total transferred: 45125899 bytes
HTML transferred: 5950668 bytes
Requests per second: 1191.68 [#/sec] (mean)
Time per request: 839.153 [ms] (mean)
Time per request: 0.839 [ms] (mean, across all concurrent requests)
Transfer rate: 105.03 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 21 256.5 1 9015
Processing: 9 709 3949.7 117 69845
Waiting: 0 460 2441.9 116 67652
Total: 29 730 3957.6 119 69846 Percentage of the requests served within a certain time (ms)
50% 119
......
100% 69846 (longest request)
结果分析:
(1)从平均的response time:bottle(0.839) < flask(1.726) < webpy(3.067)
(2)从TPS:bottle(1191.68) > flask(579.38) > webpy(326.05)
(3)从Failed请求数:bottle(1191.68) > flask(579.38) > webpy(326.05)
[注]:为什么会有fail?从uwsgi的log看来,报了一些(Write IO Error),这个错误的原因是当uwsgi处理完请求返回结果时,发现客户端已经断开了连接,结果无处可送,则Writer IO Error。一般情况下,这是由于客户端响应太慢,导致了客户端timeout所致。看起来响应还是足够快的,并且并发只有1000,这里为何会timeout,不是十分确定根本原因。
(4)从CPU:
- webpy最耗CPU,其中黄色部分是(CPU system time),看起来系统调用比其余两个高很多。
- bottle比flask略高一些,总体是上,相差不算过大。
结论:性能排序结果为webpy < flask < bottle。
那是不是就意味着应该选性能最好的bottle?这也不应太绝对,因为在开发项目时,不同的人可能对不同的项目的熟悉程度不一样,另外flask可能有广泛的插件支持,所以选择最适合自己的,而不是一昧追求性能最快。
说明:本文试图比较三者之间的性能,而不是测试三个模块的性能极限(例如我都没有说明测试机的配置,因为这里测试的是同一配置下的相对值)。如果测试三个模块的性能极限,可能server配置、以及uwsgi的配置均需要根据测试进行优化,在这里不是重点,不再赘述。
webpy/flask/bottle性能测试的更多相关文章
- python常用web框架性能测试(django,flask,bottle,tornado)
测了一下django.flask.bottle.tornado 框架本身最简单的性能.对django的性能完全无语了. django.flask.bottle 均使用gunicorn+gevent启动 ...
- 高并发异步uwsgi+web.py+gevent
为什么用web.py? python的web框架有很多,比如webpy.flask.bottle等,但是为什么我们选了webpy呢?想了好久,未果,硬要给解释,我想可能原因有两个:第一个是兄弟项目组用 ...
- python三大web框架Django,Flask,Flask,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架
Python几种主流框架 从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python We ...
- Django,Flask,Tornado三大框架对比,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架
Django 与 Tornado 各自的优缺点Django优点: 大和全(重量级框架)自带orm,template,view 需要的功能也可以去找第三方的app注重高效开发全自动化的管理后台(只需要使 ...
- 客官,您的 Flask 全家桶请收好
http://www.factj.com/archives/543.html Flask-AppBuilder - Simple and rapid Application buil ...
- python课程
课程大纲 一.语言基础(5周) 数据类型 流程控制 模块 函数.迭代器.装饰器 递归.迭代.反射 面向对象编程 模拟人生游戏开发 二.网络编程(4周) Socket c/s编程.Twisted网络框架 ...
- python 常用库整理
python 常用库整理 GUI 图形界面 Tkinter: Tkinter wxPython:wxPython pyGTK:PyGTK pyQt:pyQt WEB框架 django:django w ...
- Web框架的原理和Django初识
一.Web框架的本质 1.本质 实际上Web应用本质上就是一个socket服务端, 而用户的浏览器就是一个socket客户端. 2.最原始的web框架 socket服务端 import socket ...
- python wsgi 简介
wsgi全称是"Web Server Gateway Interfacfe",web服务器网关接口,wsgi在python2.5中加入,是web服务器和web应用的标准接口,任何实 ...
随机推荐
- CSS样式 vertical-align:middle 垂直居中生效情况
vertical-align:middle 是依赖div内子元素最高的行高来实现对某元素居中的 -------不存在浮动时可以直接生效垂直居中 HTML .box1{ display: table- ...
- RabbitMQ延迟队列
rabbitmq延迟队列 rabbitmq实现延迟队列用了rabbitmq-delayed-message-exchange插件,需要提前安装,并启用. 原理 其原理是通过Exchange来实现延迟功 ...
- java直接计算一个算术题
import javax.script.ScriptEngine;import javax.script.ScriptEngineManager;import javax.script.ScriptE ...
- MySQL INSERT语句
insert的语法 INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [(col_name,...)] ...
- Putting Apache Kafka To Use: A Practical Guide to Building a Stream Data Platform-part 1
转自: http://www.confluent.io/blog/stream-data-platform-1/ These days you hear a lot about "strea ...
- UVA 814 The Letter Carrier's Rounds(JAVA基础map)
题解:就是按照题目模拟就好 但是这个题目让我发现了我Java里面许多问题 具体看代码,但是还是分为这几个方面 属性的作用域问题,缓冲区问题,map与list映射的问题,输出多个空格不一定是/t,反转思 ...
- 读取文件并找出年龄最大的N个人-兰亭集市笔试题
C++ code: #include <iostream> #include <fstream> #include <map> #include <strin ...
- angularjs1 自定义图片查看器(可旋转、放大、缩小、拖拽)
笔记: angularjs1 制作自定义图片查看器(可旋转.放大.缩小.拖拽) 2018-01-12 更新 可以在我的博客 查看我 已经封装好的 纯 js写的图片查看器插件 博客链接 懒得把 ...
- [Vue]webpack的require与require.context
1.require 1.1完整路径的require语句: require('tools'); //preset alias tools require('./js/main'); 1.2带表达式的 r ...
- key中断
1 中断,很短的时间过去,然后回来.2 信号,软中断,而中断属于硬中断.3 实时内核,和分时内核.4 同步,预先知道发生,异步,预先不知道要发生,中断属于异步.5 arm一次执行一个中断.6 irq中 ...