python - 为什么tornado 和 gevent 组合起来会比原生 tornado 更快?
怪我咯
怪我咯 2017-04-17 13:45:34
0
5
1033

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

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

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(5)
左手右手慢动作

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.

大家讲道理

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.

黄舟

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.

迷茫

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.

阿神

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!