【问题标题】:Performance difference between @gen.engine and @gen.coroutine Tornado 4.4.2@gen.engine 和 @gen.coroutine Tornado 4.4.2 之间的性能差异
【发布时间】:2017-08-05 08:30:30
【问题描述】:

我有一个用@gen.coroutine 装饰的处理程序方法:

class MyHandler(tornado.web.RequestHandler):

    @gen.coroutine
    def post(self):

        ...

```

当我对此 API 执行性能测试时,我的服务每秒最多可以执行 3 或 4 个请求。

如果我只是将 @gen.coroutine 更改为 @gen.engine 并执行完全相同的性能测试,则该服务每秒可以处理大约 50 个请求。

这两个装饰器之间的性能差异的原因是什么?我的@gen.engine 使用错误吗?

谢谢!

【问题讨论】:

    标签: asynchronous tornado coroutine


    【解决方案1】:

    这两个装饰器之间不应该有任何性能差异。您确定您的应用程序在这两种情况下都在做同样的事情吗?在RequestHandler.post 的实现上,简单地将@gen.coroutine 替换为@gen.engine 并不等同。您还必须添加@tornado.web.asynchronous,这是@engine 所必需的,但不与@coroutine 一起使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 2012-05-26
      • 2013-09-02
      • 2014-03-15
      • 2010-12-07
      • 2017-06-05
      • 2011-12-03
      相关资源
      最近更新 更多