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

转自:http://blog.csdn.net/woshiaotian/article/details/17839677

实验前提: 

安装twisted

安装tornado 

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

twisted select模式

[python]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. from twisted.internet import selectreactor  
  2. selectreactor.install()  
  3.   
  4. from twisted.internet import reactor  
  5. from twisted.web import server, resource  
  6.   
  7.   
  8. class Simple(resource.Resource):  
  9.     isLeaf = True  
  10.     def render_GET(self, request):  
  11.         return "<html>Hello, world!</html>"  
  12.   
  13. import sys  
  14. print sys.modules['twisted.internet.reactor']  
  15. site = server.Site(Simple())  
  16. reactor.listenTCP(8080, site)  
  17. reactor.run()  

twisted epoll模式

[python]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. from twisted.internet import epollreactor  
  2. epollreactor.install()  
  3.   
  4. from twisted.internet import reactor  
  5. from twisted.web import server, resource  
  6.   
  7.   
  8. class Simple(resource.Resource):  
  9.     isLeaf = True  
  10.     def render_GET(self, request):  
  11.         return "<html>Hello, world!</html>"  
  12.   
  13. import sys  
  14. print sys.modules['twisted.internet.reactor']  
  15. site = server.Site(Simple())  
  16. reactor.listenTCP(8080, site)  
  17. reactor.run()  

tornado 服务器

[python]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. import tornado.ioloop  
  2. import tornado.web  
  3. import time  
  4. class MainHandler(tornado.web.RequestHandler):  
  5.     def get(self):  
  6.         self.write("Hello, world")  
  7.     #time.sleep(0.5)  
  8.     pass  
  9.     def post(self):  
  10.     pass  
  11.   
  12. application = tornado.web.Application([  
  13.     (r"/", MainHandler),  
  14. ])  
  15.   
  16. if __name__ == "__main__":  
  17.     application.listen(8080)  
  18.     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 plain copy 在CODE上查看代码片 派生到我的代码片
  1. a = 123.45  
  2. for i in range(1000):  
  3.     a =  a * a  

类型request/sec
tornado843.39
twisted-select735.16
twisted-epoll709.41


结论: tornado会优先使用epoll模型,但是其处理速度明显超过twisted

但对于twisted使用epoll模型速度反不如使用select模型,实在令人费解。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值