uWSGI使用介绍及性能测试结果

uWSGI使用介绍及性能测试结果

uwsgi介绍

uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。

要注意 WSGI / uwsgi / uWSGI 这三个概念的区分。

1.WSGI是一种Web服务器网关接口。它是一个Web服务器(如nginx,uWSGI等服务器)与web应用(如用Flask框架写的程序)通信的一种规范。

2.uwsgi是一种线路协议而不是通信协议,在此常用于在uWSGI服务器与其他网络服务器的数据通信。

3.而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。

4.uwsgi协议是一个uWSGI服务器自有的协议,它用于定义传输信息的类型(type of information),每一个uwsgi packet前4byte为传输信息类型描述,它与WSGI相比是两样东西。

uwsgi性能非常高

性能对比柱状图.png

uWSGI的主要特点如下

超快的性能

低内存占用(实测为apache2的mod_wsgi的一半左右)

多app管理(终于不用冥思苦想下个app用哪个端口比较好了-.-)

详尽的日志功能(可以用来分析app性能和瓶颈)

高度可定制(内存大小限制,服务一定次数后重启等)

总而言之uwgi是个部署用的好东东,正如uWSGI作者所吹嘘的:

If you are searching for a simple wsgi-only server, uWSGI is not for you, but if you are building a real (production-ready) app that need to be rock-solid, fast and easy to distribute/optimize for various load-average, you will pathetically and morbidly fall in love (we hope) with uWSGI.

uWSGI 安装

下载uWSGI 2.0.18,安装:

python setup.py install

uWSGI 代码示例

simple_app.py代码测试文件

#file:simple_app.py

import uwsgi

import os

print("!!! uWSGI version:", uwsgi.version)

def ciao():

print("modifica su /tmp")

def ciao2():

print("nuovo uwsgi_server")

print os.getpid()

counter = 0

#if uwsgi.load_plugin(0, 'plugins/example/example_plugin.so', 'ciao'):

# print "example plugin loaded"

#else:

# print "unable to load example plugin"

#uwsgi.event_add(uwsgi.EVENT_FILE, "/tmp", ciao)

#uwsgi.event_add(uwsgi.EVENT_DNSSD, "_uwsgi._tcp", ciao2)

#uwsgi.event_add(uwsgi.EVENT_TIMER, 1000, ciao2)

uwsgi.post_fork_hook = ciao2

def application(env, start_response):

global counter

#print(env)

start_response('200 Ok', [('Content-type', 'text/plain')])

yield "hello world"

yield "hello world2"

for i in range(1,1000):

yield str(i)

yield "\n"

yield str(counter)

counter += 1

simple_app.ini配置文件如下:

[uwsgi]

socket = /tmp/%n.sock

processes = 4

master = 1

启动脚本

uwsgi --http-socket :9099 --wsgi-file simple_app.py --ini simple_app.ini

测试结果

uWSGI 4进程,使用jmeter并发量10线程/10000次,吞吐量大概在2104.7/s。

linux uWSGI进程运行截图.png

jmeter性能测试结果图.png

Label

# 样本

平均值

吞吐量

uwsgi/test

100000

4

2104.73144

相关推荐

鹦鹉为什么歪头看人
mobile48365-365

鹦鹉为什么歪头看人

📅 08-11 👁️ 1901
gta任务中断 稍后回来进行任务怎么办 gta5任务中断稍后再回来怎么解决
外围365彩票软件官方app下载

gta任务中断 稍后回来进行任务怎么办 gta5任务中断稍后再回来怎么解决

📅 07-16 👁️ 1395
立凯名字含义:
365速发彩票app下载旧版

立凯名字含义:

📅 07-12 👁️ 2719