您的位置:首页 > 其它

关于web服务器的性能测试实验

2014-01-12 18:20 459 查看
转自:/article/9704212.html

实验前提:

安装twisted

安装tornado

实验1: 对比twisted的两种网络模型select模式和epoll模式的web服务器(单线程)与tornado的web服务器(单线程)的性能差异

twisted select模式

[python] view
plaincopy





from twisted.internet import selectreactor

selectreactor.install()

from twisted.internet import reactor

from twisted.web import server, resource

class Simple(resource.Resource):

isLeaf = True

def render_GET(self, request):

return "<html>Hello, world!</html>"

import sys

print sys.modules['twisted.internet.reactor']

site = server.Site(Simple())

reactor.listenTCP(8080, site)

reactor.run()

twisted epoll模式

[python] view
plaincopy





from twisted.internet import epollreactor

epollreactor.install()

from twisted.internet import reactor

from twisted.web import server, resource

class Simple(resource.Resource):

isLeaf = True

def render_GET(self, request):

return "<html>Hello, world!</html>"

import sys

print sys.modules['twisted.internet.reactor']

site = server.Site(Simple())

reactor.listenTCP(8080, site)

reactor.run()

tornado 服务器

[python] view
plaincopy





import tornado.ioloop

import tornado.web

import time

class MainHandler(tornado.web.RequestHandler):

def get(self):

self.write("Hello, world")

#time.sleep(0.5)

pass

def post(self):

pass

application = tornado.web.Application([

(r"/", MainHandler),

])

if __name__ == "__main__":

application.listen(8080)

tornado.ioloop.IOLoop.instance().start()

测试方法:

在本机使用ab命令进行压测

ab -c 5 -n 10000 http://localhost:8080/
测试结果:

类型request/sec
tornado1469.23
twisted-select1148.36
twisted-epoll1101.66
在http的请求处理逻辑中加入消耗CPU的浮点运算,,结果近似

[python] view
plaincopy





a = 123.45

for i in range(1000):

a = a * a

类型request/sec
tornado843.39
twisted-select735.16
twisted-epoll709.41
结论: tornado会优先使用epoll模型,但是其处理速度明显超过twisted

但对于twisted使用epoll模型速度反不如使用select模型,实在令人费解。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: