python web 并发 性能_Python Web Server的性能测试

因为换了nginx就不再使用mod_wsgi来跑web.py应用了,现在用的是gevent-wsgi,效果还不错。但还是想试试别的,比如传说中超级猛的meinheld什么的。

软硬件环境

硬件:

一台04年初购置的IBM X235服务器,CPU为Xeon 2.4G两颗,内存1G,100M网卡。

软件:

Ubuntu Server 10.04 LTS

Apache 2.2.14

Nginx 0.7.65

Python 2.6.5

web.py 0.37

mako 0.7.2

sqlalchemy 0.7.8

gevent 0.13.7

gunicorn 0.14.6

meinheld 0.4.15

测试代码

有五个版本,分别是:

最基本的WSGI helloworld

defapplication(environ, start_response):

status ='200 OK'

resp ="Hello world!"

resp_headers = [('Content-type','text/plain;charset=utf-8')]

start_response(status, resp_headers)

return[resp]

def application(environ, start_response):

status = '200 OK'

resp = "Hello world!"

resp_headers = [('Content-type','text/plain;charset=utf-8')]

start_response(status, resp_headers)

return [resp]

最基本的web.py your IP

classyourip:

defGET(self):

return"Your IP is : %s"% web.ctx.ip

class yourip:

def GET(self):

return "Your IP is : %s" % web.ctx.ip

加了mako模板的web.py

classonlymako(BaseHandler):

@expose("yourip")

defGET(self):

returndict(yourip=web.ctx.ip)

class onlymako(BaseHandler):

@expose("yourip")

def GET(self):

return dict(yourip=web.ctx.ip)

加了数据库的web.py

classonlydb:

defGET(self):

created = web.ctx.provider.once_access(web.ctx.ip)

return"You have logged : %s"% created

class onlydb:

def GET(self):

created = web.ctx.provider.once_access(web.ctx.ip)

return "You have logged : %s" % created

和同时加了数据库和mako模板的web.py —— 这也是最接近实际应用的情况

classmakodb(BaseHandler):

@expose("index")

defGET(self):

created = web.ctx.provider.once_access(web.ctx.ip)

returndict(created=created)

class makodb(BaseHandler):

@expose("index")

def GET(self):

created = web.ctx.provider.once_access(web.ctx.ip)

return dict(created=created)

测试目标

五种运行环境:

web.py的测试环境app.run

web.py+gevent-WSGI

gunicorn默认(sync)

gunicorn+gevent

gunicorn+meinheld

gunicorn使用 -w 4 参数,经实际比较过,这个参数并不能有效增加rps,但在高并发测试情况下可以在一定程度上减少失败率。

测试方式

ApacheBench 2.3(Ubuntu Desktop 12.04)

RPS测试参数为 -n 200 -c 22 测五次取rps平均值。

之所以用这样比较小的参数,是因为再高了,其中某些测试就通不过了。

测试结果

RPS测试WSGI helloworldWeb.py YourIPWeb.py+MakoWeb.py

+SQLAlchemy

(SQLite)Web.py+Mako

+SQLAlchemy

(SQLite)Web.py

+SQLAlchemy

(Postgresql)Web.py+Mako

+SQLAlchemy

(Postgresql)

Web.py app.run

130

93

75*

45*

59

40

web.py+gevent

422

130

82

54

74

53

gunicorn default

854

439

136

93

66

90

62

gunicorn+gevent

695

291

115

74

56

78

56

gunicorn+meinheld

3565

682

160

84

65

98

64

其中加了“*”的数字发生了数据库错误,仅供参考。

另外,用同样的参数测了一下Apache2处理静态文件的rps为:1780,nginx为:2951。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值