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

实验前提: 

安装twisted

安装tornado 

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

twisted select模式

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模式

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 服务器

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的浮点运算,,结果近似

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模型,实在令人费解。





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值