gunicorn、uwsgi性能测试

目的,测试在不同的部署方式下的性能。

硬件环境

Intel Core i5-3230M CPU @ 2.60GHz × 4

内存: 7.4 GiB

操作系统: Ubuntu 14.04 64 位

测试代码(hello.py)

from bottle import Bottle, run

app = Bottle()

@app.route(‘/hello‘)
def hello():
    return "Hello World!"

if __name__ == "__main__":
    run(app, host=‘localhost‘, port=8000)

uwsgi

uwsgi_python --htket=:8000 --workers=2 --wsgi-file hello.py --callable app 2>/dev/null

结果:

ab -c 100 -n 50000 "http://localhost:8000/hello"
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests

Server Software:        
Server Hostname:        localhost
Server Port:            8000

Document Path:          /hello
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   3.288 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      4550000 bytes
HTML transferred:       600000 bytes
Requests per second:    15206.71 [#/sec] (mean)
Time per request:       6.576 [ms] (mean)
Time per request:       0.066 [ms] (mean, across all concurrent requests)
Transfer rate:          1351.38 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   1.3      2       6
Processing:     1    5   1.3      4      14
Waiting:        1    4   1.7      4      12
Total:          4    7   0.8      6      19
WARNING: The median and mean for the total time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      6
  66%      7
  75%      7
  80%      7
  90%      7
  95%      7
  98%      8
  99%     11
 100%     19 (longest request)

gunicorn

gunicorn -w 2 hello:app

结果:

ab -c 100 -n 50000 "http://localhost:8000/hello"
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 5000 requests
Completed 10000 requests
Completed 15000 requests
Completed 20000 requests
Completed 25000 requests
Completed 30000 requests
Completed 35000 requests
Completed 40000 requests
Completed 45000 requests
Completed 50000 requests
Finished 50000 requests

Server Software:        gunicorn/19.3.0
Server Hostname:        localhost
Server Port:            8000

Document Path:          /hello
Document Length:        12 bytes

Concurrency Level:      100
Time taken for tests:   8.821 seconds
Complete requests:      50000
Failed requests:        0
Total transferred:      8600000 bytes
HTML transferred:       600000 bytes
Requests per second:    5668.37 [#/sec] (mean)
Time per request:       17.642 [ms] (mean)
Time per request:       0.176 [ms] (mean, across all concurrent requests)
Transfer rate:          952.11 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       7
Processing:     3   18   2.0     17      34
Waiting:        3   17   2.0     17      34
Total:         10   18   2.0     17      36

Percentage of the requests served within a certain time (ms)
  50%     17
  66%     17
  75%     18
  80%     18
  90%     19
  95%     23
  98%     23
  99%     24
 100%     36 (longest request)

总结

方案 并发 最大响应时间(ms)
uwsgi 15206 19
gunicorn 5668 36
时间: 2025-01-09 23:36:50

gunicorn、uwsgi性能测试的相关文章

centos7 + nginx+django 运行环境

1.easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的 首先安装easy_install 下载地址:https://pypi.python.org/pypi/ez_setup tar -zxf ez_setup-0.9.tar.gz cd ez_setup-0.9 python ez_setup.py 安装好easy_install 之后 再安装pip 下载地址:https://pypi.python.org/pypi/pip tar -zxf pi

框架1

目的 实现一个简单的web框架 只实现rest(有一整套严格的规范) 常见框架有 : Rails pyramid bottle web.py flask 理解框架实现原理 动态网页的发展历程最早的时候,web就是一些静态文件 最早的动态页面是CGI实现的(动态生成返回的内容) CGI怎么工作? 当请求一个地址的时候,http服务器就会启动一个外部程序,并且把外部程序的输出返回给用户. CGI协议规范了http和外部程序的通信方式通信方式:输入:通过环境变量   http设置环境变量输出:通过标准

Django -- 整合apache、nginx

前面章节我们都是通过python manage.py runserver运行服务器,访问django,但这只适用于测试环境.当项目正式发布后,我们需要一个稳定可持续的服务器,比如apache.nginx等等.接下来我们将用apache.nginx启动服务器. wsgi:一种实现了python解析的通用接口标准/协议,实现了python web程序与服务器交互. uwsgi:他也是一种通信协议,是uWSGI服务器自有的协议: uWSGI:一种python的web服务器,实现了uwsgi.WSGI两

列举一些常见的Python HTTP服务器

要使 Python 写的程序能在 Web 上被访问,还需要搭建一个支持 Python 的 HTTP 服务器.下面列举一些常见的 Python HTTP 服务器,以及它们目前的大致发展情况,以便用户的对比选择: Name Version http 1.1 Flavour Repo. Community Gunicorn 0.6.4 No processor/thread GIT #gunicorn uWSGI Trunk (253) Yes processor/thread repo Mailin

还能不能愉快地起一个web服务啦?——1st Step!白话http和代码交互的那点儿事儿~

学写python的时候,我们多多少少都接触到了web程序,然而你有没有想过,当浏览器发送了一个http请求时,等待接收这个请求的后端代码是一种什么样的思想感情? 就像下面这张图里画的一样,后端也许是一段java代码,也许是php代码,当然,如果代码出自我手,最可能的还是一段python代码.这就好比,当你在社交软件上给一个陌生人发了一条消息,对面这个人可能是英国人.印度人也有可能是一只羊或者一只狗...那么问题来了,他们怎么知道你在说啥?当然了,在web服务的世界里没有现实中那么复杂,我们不需要

Flask基础介绍

1. 介绍 Flask是一种使用Python 编写的轻量级Web应用框架, 实现了基础的核心, 用extension增加其他功能它的WSGI工具箱采用Werkzeug, 模板引擎则使用Jinja2 2. Flask使用 2.1 路由 from flask import Flask app = Flask(__name__) @app.route("/url") def handle_url: return "Something" 2.2 反向路由 from flas

Django部署

前段时间,由于实验室项目的需要,要搭建一个web服务器,可怜我只会写python,所以就去研究了一下Django.学习Django是一个愉快的过程,本来就该如此嘛,Python提倡INTERESTING TO CODE,所以很快,我就完成了Django的本地部署,然而在把Django搭到服务器上的是,却是让我捣鼓了一个星期,真真是把我坑苦了. 1.我的环境 在把Django搭建到Apache上时候,首先你需要明确你使用的Django和Apache的版本,嗯,还有Python的版本(这很重要)!

第9章 py web框架考察点

py WSGI与web框架常考点 考点聚焦 WSGI, 常见Web框架 常用的py web框架Django/Flask/Tornado对比 Web框架的组成(淡化框架,加强基础) 什么是WSGI? Python Web Server Gateway Interface(PEP 333) 解决Python Web Server乱象mod_python, CGI, FastCGI等 描述Web Server(Gunicorn/uWSGI)如何与web框架交互, Web框架如何处理请求 def app

Python后端技术栈(七)--web框架

1.7 Python web 框架 上篇文章对数据库中的一些经典问题做了总结,比如关系型数据库中事务.隔离级别.慢查询分析.索引原理以及非关系型数据库的数据结构等等. 本篇文章将开始 Python web 框架的相关内容,开始咯~ 1.7.1 Python WSGI 与 web 框架 1.7.1.1 什么是 WSGI ? 我们经常使用 uwsgi/gunicorn 部署 Django/Flask 应用,但是大家思考过一个问题没有,为什么不同的框架可以部署在相同的 web 服务器上呢?比如为什么