V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
herozem
V2EX  ›  分享创造

写了一个基于 uvloop 的 web 框架

  •  
  •   herozem · 2017-04-22 18:34:44 +08:00 · 4376 次点击
    这是一个创建于 2554 天前的主题,其中的信息可能已经有所发展或是发生改变。

    项目主页: https://github.com/jiajunhuang/storm

    uvloop 真不是一般的快,用 APACHE BENCHMARK 跑分,其中 IOPS :

    • storm 约为 13106.53
    • Tornado 约 2015.07
    • Sanic 约 17353.71

    因为不喜欢 sanic 和 flask 这种函数形式的写法,相比更喜欢 web.py 这种 class 形式的写法,于是自己写了一个玩玩,示例代码为:

    import logging
    
    from storm.app import Application
    from storm.handler import RequestHandler
    
    
    class RootHandler(RequestHandler):
        def initialize(self):
            logging.debug("initialize been called")
    
        async def get(self):
            self.write({
                "hello": "world"
            })
    
    
    handler_classes = [
        (r"/", RootHandler),
    ]
    
    Application(
        handler_clses=handler_classes,
        debug=False,
    ).run()
    

    代码整体上还处于雏形状态,很多影响性能的地方也没有做处理,目前的计划是:

    1, 支持更完整的 HTTP 协议
    2, 加入对模板的支持
    3, 减少对象的消耗,提高性能,争取追平甚至超过 Sanic
    
    5 条回复    2017-07-05 17:20:59 +08:00
    isombyt
        1
    isombyt  
       2017-04-24 02:51:56 +08:00
    flask: flask.views.MethodView 可以实现示例的功能

    sanic: 跟 flask View 一样的原理,搭配 app.route(uri)(MethodView.as_view())也可以实现

    不妨试试测下用这方法在 sanic 实现同样的功能的性能如何。另外, sanic 也是支持 uvloop 的。


    如果铁了要造轮子硬刚 sanic 的心,只要能实现 WSGI 协议就可以爆 sanic 了。参见
    https://github.com/channelcat/sanic/issues/250

    IOPS 的跑分真的没有太大参考价值。
    herozem
        2
    herozem  
    OP
       2017-04-24 09:26:24 +08:00
    @isombyt 谢谢,上面的 sanic 是已经用上了 uvloop 的~
    smdx
        3
    smdx  
       2017-04-24 10:28:43 +08:00 via Android
    牛牛
    crabRunning
        4
    crabRunning  
       2017-04-24 15:06:33 +08:00
    先不说 python3.5 是一道无法逾越的坎
    raytlty
        5
    raytlty  
       2017-07-05 17:20:59 +08:00
    大牛
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2849 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 06:08 · PVG 14:08 · LAX 23:08 · JFK 02:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.