Home  >  Q&A  >  body text

python - 为什么tornado 和 gevent 组合起来会比原生 tornado 更快?

tornado 不是已经异步了吗, 为什么加上 gevent 后会更快?

提问来自于这篇 blog, 速度测试

怪我咯怪我咯2742 days ago1038

reply all(5)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 13:47:34

    The guess is that gevent is a C module, and tornado packet reassembly and HTTP protocol parsing are all written in Python. For example, regular expressions are used to parse HTTP headers. . .
    In tornado-over-gevent, tornado runs in wsgi mode, and HTTP protocol parsing and other work are completed by gevent.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:47:34

    As for the question asked by the questioner, asynchronous is not necessarily faster than synchronous. This depends on the specific application scenario.

    In comparison, if it is not concurrent and not for blocking operations. It’s hard to say which one is faster, synchronous or asynchronous.

    Python’s concurrency technology is roughly multi-threading, multi-process, and coroutine. You can refer to this article

    tornado can be asynchronous or synchronous, it depends on how to use it.

    reply
    0
  • 黄舟

    黄舟2017-04-17 13:47:34

    Original text says:

    从上面结果可能看出Tornado比Flask快很多. 而Gevent可以让Tornado更快一些, 但快不了很多.
    

    I have seen such test conclusions in other articles. Since it's not much faster, it's better not to use it.

    reply
    0
  • 迷茫

    迷茫2017-04-17 13:47:34

    tornaod provides a magic stackcontext manager to provide context management of coroutines, and this is implemented by tornado. And gevent completes the same work in C. But there is not much difference in efficiency between the two.
    Another point worth mentioning is that tornado actually provides a @coroutine mechanism, which makes synchronous writing also consume efficiency.

    reply
    0
  • 阿神

    阿神2017-04-17 13:47:34

    Listen to what my boss said, gevent uses greenlet + epoll. Greenlet customizes the stack. Greenlet is a bit similar to goroutine. It can achieve parallelism. Tornado just implements epoll by itself.

    reply
    0
  • Cancelreply