web框架并发1--tornado

当下好多“王婆”卖瓜, 一个劲说架构并发能力 10万、100万, 但看到大家实际并发测试, 确少得可怜。

先说说tornado的并发能力

一、环境

1. python环境

Python 2.7.6

2. tornado环境

4.2.1

3. nginx环境

nginx version: nginx/1.9.9

4. 服务器和操作系统环境

物理双核、逻辑四十核, centos 7

二、tornado 单进程直接测试

1. 代码:

import tornado

import tornado.web

import tornado.httpserver

import sys, signal, time

def sig_handler(sig, frame):

    tornado.ioloop.IOLoop.instance().add_callback(shutdown)

def shutdown():

    HTTP_SERVER.stop()

    io_loop = tornado.ioloop.IOLoop.instance()

    io_loop.stop()

class MainHandler(tornado.web.RequestHandler):

    @tornado.gen.coroutine

    def get(self):

        self.finish()

class Application(tornado.web.Application):

    def __init__(self):

        settings = dict(

            debug=False,

        )

        handlers = [

            (r"/", MainHandler),

        ]

        super(Application,self).__init__(handlers,**settings)

def main():

    global HTTP_SERVER

    try:

        HTTP_SERVER = tornado.httpserver.HTTPServer(Application())

        HTTP_SERVER.listen(sys.argv[1])

    except Exception, ex:

        print "Create and listen http server failed! Exception: %s"% str(ex)

        quit()

    signal.signal(signal.SIGTERM, sig_handler)

    signal.signal(signal.SIGINT, sig_handler)

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

if __name__ == "__main__":

    try:

        main()

    except Exception, ex:

        print "Ocurred Exception: %s" % str(ex)

        quit()

2. 执行命令

python server.py --port=40001

3. webbench 测试结果1(1251.4qps):

webbench -c 1 -t 10 http://127.0.0.1:40001/

Speed=75084 pages/min, 279062 bytes/sec.

Requests: 12514 susceed, 0 failed.

经过多次, 不同的客户端数量测试结果相差无几。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 引言 以Django为代表的python web应用部署时采用wsgi协议与服务器对接(被服务器托管),而这类服务...
    大熊_7d48阅读 2,065评论 0 3
  • Python语言特性 1 Python的函数参数传递 看两个如下例子,分析运行结果: 代码一: a = 1 def...
    时光清浅03阅读 505评论 0 0
  • Python语言特性 1 Python的函数参数传递 看两个如下例子,分析运行结果: 代码一: a = 1 def...
    伊森H阅读 3,083评论 0 15
  • 官方文档中文文档Tornado概览浅谈Python Web 框架:Django, Twisted, Tornado...
    一只写程序的猿阅读 42,195评论 7 50
  • 朋友圈里有位同样热爱文字的大哥哥,每次聊天,就一个字“忙”。我总会回复辛苦并幸福着。他家里有俩男孩,自己开着一个小...
    涟漪dl阅读 287评论 0 1