这三个都是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性能测试的更多相关文章

  1. python常用web框架性能测试(django,flask,bottle,tornado)

    测了一下django.flask.bottle.tornado 框架本身最简单的性能.对django的性能完全无语了. django.flask.bottle 均使用gunicorn+gevent启动 ...

  2. 高并发异步uwsgi+web.py+gevent

    为什么用web.py? python的web框架有很多,比如webpy.flask.bottle等,但是为什么我们选了webpy呢?想了好久,未果,硬要给解释,我想可能原因有两个:第一个是兄弟项目组用 ...

  3. python三大web框架Django,Flask,Flask,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架

    Python几种主流框架 从GitHub中整理出的15个最受欢迎的Python开源框架.这些框架包括事件I/O,OLAP,Web开发,高性能网络通信,测试,爬虫等. Django: Python We ...

  4. Django,Flask,Tornado三大框架对比,Python几种主流框架,13个Python web框架比较,2018年Python web五大主流框架

    Django 与 Tornado 各自的优缺点Django优点: 大和全(重量级框架)自带orm,template,view 需要的功能也可以去找第三方的app注重高效开发全自动化的管理后台(只需要使 ...

  5. 客官,您的 Flask 全家桶请收好

    http://www.factj.com/archives/543.html Flask-AppBuilder          - Simple and rapid Application buil ...

  6. python课程

    课程大纲 一.语言基础(5周) 数据类型 流程控制 模块 函数.迭代器.装饰器 递归.迭代.反射 面向对象编程 模拟人生游戏开发 二.网络编程(4周) Socket c/s编程.Twisted网络框架 ...

  7. python 常用库整理

    python 常用库整理 GUI 图形界面 Tkinter: Tkinter wxPython:wxPython pyGTK:PyGTK pyQt:pyQt WEB框架 django:django w ...

  8. Web框架的原理和Django初识

    一.Web框架的本质 1.本质 实际上Web应用本质上就是一个socket服务端, 而用户的浏览器就是一个socket客户端. 2.最原始的web框架 socket服务端 import socket ...

  9. python wsgi 简介

    wsgi全称是"Web Server Gateway Interfacfe",web服务器网关接口,wsgi在python2.5中加入,是web服务器和web应用的标准接口,任何实 ...

随机推荐

  1. ISSCC 2017论文导读 Session 14 Deep Learning Processors,A 2.9TOPS/W Deep Convolutional Neural Network SOC

    最近ISSCC2017大会刚刚举行,看了关于Deep Learning处理器的Session 14,有一些不错的东西,在这里记录一下. A 2.9TOPS/W Deep Convolutional N ...

  2. 转:eclipse与myeclipse恢复已删除的文件和代码

  3. C#(Wpf)实现小键盘

    花了一天时间小键盘基本功能已完成,先看看效果图吧! 默认: Shift: Caps Lock: Button style <Style x:Key="KeyButton" T ...

  4. 《Think in Java》(十三)字符串

    学完这章后,对 Java 字符串有了重新的认识.自己也看了下 CharSequence,String,StringBuilder,StringBuffer 等类的实现代码.

  5. python 读取、保存、二值化、灰度化图片+opencv处理图片的方法

    http://blog.csdn.net/johinieli/article/details/69389980

  6. 设计模式--适配器模式C++实现

    适配器模式C++实现 1定义Adapter 将一个类的接口变成客户端所需要的另外一种借口,从而使远不因为接口不匹配而无法合作的两个雷能够一起工作 又叫变压器模式,包装模式Wrapper 2类图 角色分 ...

  7. day39 算法基础

    参考博客: http://www.cnblogs.com/alex3714/articles/5474411.html http://www.cnblogs.com/wupeiqi/articles/ ...

  8. pip 使用总结

    pip的安装: Windows Python2.7 以上的版本均自带pip,安装的时候记得勾选对应的选项即可. 安装easy_install, 通过easy_install pip 下载[easy_s ...

  9. 转:kafka入门

    一.基本概念 介绍 Kafka是一个分布式的.可分区的.可复制的消息系统.它提供了普通消息系统的功能,但具有自己独特的设计. 这个独特的设计是什么样的呢? 首先让我们看几个基本的消息系统术语:Kafk ...

  10. C++进阶3.字节对齐 联合

    C++进阶3.字节对齐 联合 20131011 多益和金山笔试 知识漏洞 20131011 前言: 今天下午是多益网络的笔试,整体感觉还好,但是找到很多的知识漏洞.一直笔试到6:00,然后紧张的从会生 ...