Which of these frameworks / libraries would be the best choise for building modern multiuser web application? I would love to have an asynchronous webserver which will allow me to scale easly. What solution will give the best performance / scalability / most useful framework (in terms of easy of use and easy of developing)?
哪些框架/库是构建现代多用户web应用程序的最佳选择?我希望有一个异步的webserver,它可以让我轻松地扩展。什么解决方案将提供最好的性能/可伸缩性/最有用的框架(在易于使用和易于开发方面)?
It would be great if it will provide good functionality (websockets, rpc, streaming, etc).
如果它能提供良好的功能(websockets, rpc,流媒体,等等),那就太棒了。
What are the pros and cons of each solution?
每种解决方案的优缺点是什么?
4 个解决方案
#1
202
"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design". If you are building something that is similar to a e-commerce site, then you should probably go with Django. It will get your work done quick. You dont have to worry about too many technology choices. It provides everything thing you need from template engine to ORM. It will be slightly opinionated about the way you structure your app, which is good If you ask me. And it has the strongest community of all the other libraries, which means easy help is available.
Django是一个高级的Python Web框架,它鼓励快速开发和干净、实用的设计。如果您正在构建类似于电子商务网站的东西,那么您应该使用Django。这会使你的工作很快完成。你不必担心太多的技术选择。它提供了从模板引擎到ORM所需的所有东西。如果你问我,它会对你的应用程序的结构有点固执己见。而且它拥有所有其他图书馆中最强大的社区,这意味着容易提供帮助。
"Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions". Beware - "microframework" may be misleading. This does not mean that Flask is a half-baked library. This mean the core of flask is very, very simple. Unlike Django, It will not make any Technology decisions for you. You are free to choose any template engine or ORM that pleases you. Even though it comes with Jinja template engine by default, you are always free to choose our own. As far as I know Flask comes in handy for writing APIs endpoints (RESTful services).
Flask是基于Werkzeug、Jinja 2和good intentions的Python微框架。当心——“微框架”可能具有误导性。这并不意味着烧瓶是一个不成熟的库。这意味着烧瓶的核心非常非常简单。与Django不同,它不会为您做任何技术决策。您可以*选择任何您喜欢的模板引擎或ORM。尽管Jinja模板引擎是默认的,但您始终可以*地选择我们自己的模板引擎。就我所知Flask对于编写api端点(RESTful服务)非常有用。
"Twisted is an event-driven networking engine written in python". This is a high-performance engine. The main reason for its speed is something called as deferred. Twisted is built on top of deferreds. For those of you who dont know about defereds, it is the mechanism through with asynchronous architecture is achieved. Twisted is very fast. But is not suitable for writing conventional webapps. If you want to do something low-level networking stuff, twisted is your friend.
Twisted matrix是一个用python编写的事件驱动的网络引擎。这是一台高性能的发动机。其速度的主要原因被称为延迟。扭曲是建立在延迟之上的。对于那些不了解延迟的人来说,实现异步架构的机制是可行的。扭曲的非常快。但不适合编写传统的网络应用程序。如果你想做一些低级的社交活动,twisted是你的朋友。
"Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user". Tornado stands some where between Django and Flask. If you want to write something with Django or Flask, but if you need a better performance, you can opt for Tornado. it can handle C10k problem very well if it is architected right.
Tornado是一个Python web框架和异步网络库,最初由FriendFeed开发。通过使用非阻塞的网络I/O, Tornado可扩展到数万个开放连接,对于长轮询、WebSockets和其他需要与每个用户建立长期连接的应用程序来说是理想的”。龙卷风在Django和Flask之间有一些。如果您想用Django或Flask编写一些内容,但是如果需要更好的性能,可以选择Tornado。如果体系结构正确,它可以很好地处理C10k问题。
"Cyclone is a web server framework for Python that implements the Tornado API as a Twisted protocol". Now, what if you want something that is nearly as performant as Twisted but easy to write conventional webapps? Say hello to cyclone. I would prefer Cyclone over Tornado. It has an API that is very similar to Tornado. As a matter of fact, this is a fork of Tornado. But the problem is it has relativly small community. Alexandre Fiori is the only main commiter to the repo.
“Cyclone是Python的web服务器框架,将Tornado API实现为Twisted protocol”。现在,如果你想要的是一款和传统的web应用程序一样的高性能,但又很容易编写的应用程序呢?向气旋问好。比起龙卷风,我更喜欢旋风。它有一个非常类似于龙卷风的API。事实上,这是龙卷风的一个分支。但问题是它的社区相对较小。亚历山大·菲奥里是“回购”的唯一主要参与者。
"Pyramid is a general, open source, Python web application development framework. Its primary goal is to make it easier for a Python developer to create web applications." I haven't really used Pyramid, but I went through the documentation. From what I understand, Pyramid is very similar to Flask and I think you can use Pyramid wherever Flask seems appropriate and vice-versa.
金字塔是一个通用的、开源的Python web应用程序开发框架。它的主要目标是使Python开发人员更容易创建web应用程序。我没有真正使用金字塔,但我浏览了文档。根据我的理解,金字塔和烧瓶非常相似,我认为你可以在烧瓶合适的地方使用金字塔,反之亦然。
EDIT: Request to review any other frameworks are welcomed!
编辑:欢迎评论任何其他框架!
来源:http://dhilipsiva.com/2013/05/19/python-libraries-django-twisted-tornado-flask-cyclone-and-pyramid.html
#2
55
This is obviously a somewhat biased answer, but that is not the same thing as a wrong answer; you should always use Twisted. I've answered similar questions before, but since your question is not quite the same, here are some reasons:
这显然是一个有偏见的回答,但这和错误的答案是不一样的;你应该经常使用Twisted。我之前也回答过类似的问题,但由于你的问题不太一样,以下是一些原因:
"Best Performance"
Twisted continuously monitors our performance at the speed.twistedmatrix.com website. We were also one of the first projects to be monitored by PyPy's similar site, thereby assuring the good performance of Twisted on the runtime that anyone concerned with high-performance applications in Python.
Twisted在网站上持续监控我们的性能。我们也是PyPy类似站点监视的首批项目之一,因此确保了所有关心Python中的高性能应用程序的人在运行时上的Twisted的良好性能。
"Scalability"
To my knowledge, none of the listed frameworks have any built-in support for automatic scaling; they're all communication frameworks, so you have to do the work to communicate between your scaling nodes. However, Twisted has an advantage in its built-in support for local multi-processing. In fairness, there is a third-party add-on for Tornado that allows you to do the same thing. In recent releases, Twisted has added features that increase the number of ways you can share work between cores, and work is ongoing in that area. Twisted also has a couple of well-integrated, "native" RPC protocols which offer a construction-kit for whatever scaling idiom you want to pursue.
据我所知,所有列出的框架都不支持自动伸缩;它们都是通信框架,所以您必须在伸缩节点之间进行通信。然而,Twisted在内置支持本地多处理方面有优势。公平地说,Tornado支持第三方插件允许你做同样的事情。在最近的版本中,Twisted增加了一些特性,增加了在核心之间共享工作的方式,并且在这方面还在进行工作。Twisted还提供了一些集成良好的“原生”RPC协议,它们为您所追求的任何扩展习惯提供了构造工具包。
"Most Useful"
Lots of people seem to find Twisted very useful. So much so that many of them have extended it and made their extensions available to you.
很多人似乎觉得Twisted真的很有用。如此之多以至于他们中的许多人已经扩展了它并且使他们的扩展对你可用。
"Functionality"
Out of the box, Twisted includes:
Out of the box, Twisted includes:
- good support for test-driven development of all the following
- 对以下所有测试驱动开发的良好支持
- TCP servers, clients, transport layer security
- TCP服务器、客户端、传输层安全
- SSH client and server
- SSH客户机和服务器
- IMAP4, ESMTP, POP3 clients and servers
- IMAP4, ESMTP, POP3客户端和服务器
- DNS client and server
- DNS客户机和服务器
- HTTP client and server
- HTTP客户机和服务器
- IRC, XMPP, OSCAR, MSN clients and servers
- IRC, XMPP, OSCAR, MSN客户端和服务器
In this last department, at least, Twisted seems a clear winner for built-in functionality. And all this, in a package just over 2 megabytes!
至少在这最后一个部门中,Twisted matrix显然是内置功能的赢家。所有这些,在一个超过2兆字节的包里!
#3
46
I like @Glyph response. Twisted is very comprehensive, rich python framework. Twisted and Tornado have a very similar design. And I like this design very much:
我喜欢@Glyph响应。Twisted matrix是一个非常全面、丰富的python框架。Twisted和Tornado则有着非常相似的设计。我非常喜欢这个设计:
- it's fast
- 它的速度非常快
- easy to understand
- 容易理解的
- easy to extend
- 容易扩展
- doesn't require c-extensions
- 不需要c扩展
- works on PyPy.
- PyPy工作。
But I want to highlight Tornado, which I prefer and recently gain popularity. Tornado, like Twisted, uses callback style programming, but it can be inlined using tornado.gen.engine
(twisted.internet.inlineCallbacks
in Twisted).
但是我想强调龙卷风,我喜欢它,最近它流行起来了。Tornado和Twisted一样,使用回调样式编程,但可以使用Tornado .gen内联。引擎(twisted.internet.inlineCallbacks扭曲)。
Codebase
The best comment is from http://cyclone.io site. cyclone tries to mix Twisted and Tornado because:
最好的评论来自http://cyclone。io网站。旋风试图混合扭曲和龙卷风,因为:
Twisted is one of the most mature libraries for non-blocking I/O available to the public. Tornado is the open source version of FriendFeed’s web server, one of the most popular and fast web servers for Python, with a very decent API for building web applications.
Twisted matrix是面向公众的最成熟的非阻塞I/O库之一。Tornado是FriendFeed web服务器的开源版本,它是Python最流行、速度最快的web服务器之一,具有非常好的用于构建web应用程序的API。
The idea is to bridge Tornado's elegant and straightforward API to Twisted's Event-Loop, enabling a vast number of supported protocols.
其想法是将Tornado优雅而直接的API与Twisted的事件循环连接起来,从而支持大量受支持的协议。
But in 2011 tornado.platform.twisted
was out which brings similar functionality.
但在2011年tornado.platform。twisted matrix也推出了类似的功能。
Performance
Tornado has much better performance. It also works seamlessly with PyPy, and get huge gain.
Tornado有更好的表现。它还可以与PyPy无缝地工作,并获得巨大的收益。
Scalability
The same like Twisted. Tornado has tornado.process
and a lot of rpc services implemented on top of it.
同样的像扭曲。龙卷风有龙卷风。流程和许多在其之上实现的rpc服务。
Functionality
There are 71 Tornado based package, compared to 148 Twisted's and 48 Gevent's. But if you look carefully and compute median of packages upload time, you will see that Twisted ones are the oldest, then Gevent and Tornado the freshest. Furthermore there is tornado.platform.twisted
module which allows you to run code written for Twisted on Tornado.
总共有71个龙卷风包,而只有148个Twisted和48个Gevent。但是如果你仔细观察并计算出包上传时间的中值,你会发现扭曲的是最古老的,然后是Gevent和龙卷风最新鲜的。此外还有tornado.platform。twisted模块,它允许你运行被写在龙卷风上的代码。
Summary
With Tornado you can use a code from Twisted. There is no need to use cyclone which only twists your code (your code becomes more messy).
使用Tornado,你可以使用来自Twisted的代码。没有必要使用只有扭曲代码的旋风(您的代码变得更加混乱)。
As for 2014, Tornado is considered as widely accepted and default async framework which works both on python2 and python3. Also the latest version 4.x brings a lot of functionality from https://docs.python.org/dev/library/asyncio.html.
2014年,Tornado被认为是广泛接受的默认异步框架,可以在python2和python3上工作。也是最新的版本4。x从https://docs.python.org/dev/library/asyncio.html提供了很多功能。
I wrote an article, explaining why I consider that Tornado - the best Python web framework where I wrote much more about Tornado functionality.
我写了一篇文章,解释为什么我认为龙卷风是最好的Python web框架,在那里我写了更多关于龙卷风的功能。
#4
14
(UPDATE: I'm sadly surprised about how few answers here recommend or even mention Gevent—I don't think it's in proportion to the popularity, performance and ease of use of this excellent library!)
(更新:我很遗憾地感到惊讶的是,这里的答案很少,甚至很少提到gevent——我不认为它与这个优秀的库的受欢迎程度、性能和易用性成正比!)
Gevent and Twisted are not mutually exclusive, even though the contrary might seem obvious at first. There is a project called geventreactor
which allows one to relatively smoothly leverage the best of both worlds, namely:
Gevent和Twisted并不是相互排斥的,尽管相反的情况一开始看起来是显而易见的。有一个项目叫做geventreactor,它允许我们相对平稳地利用这两个方面的优点,即:
- The efficient and cheap (cooperative green) thread model of Gevent, which is much easier to program in when it comes to concurrency—frankly, Twisted's
inlineCallbacks
is simply not up to the job in terms of performance when it comes to many coroutines, and neither in terms of ease/transparency of use:yield
andDeferreds
everywhere; often hard to build some abstractions; horrifyingly useless stack traces with both bareDeferred
s as well as, and even more so with@inlineCallbacks
. - 有效和廉价的(绿色)合作Gevent的线程模型,这是更容易在谈到concurrency-frankly程序,扭曲的inlineCallbacks不胜任这项工作的性能在许多协同程序,也在缓解/使用透明度:产量和递延无处不在;通常很难建立一些抽象;令人毛骨悚然的无用的堆叠痕迹,既有简单的延迟,也有@inlineCallbacks。
- All the built-in functionality of Twisted you can ever dream of, including but not limited to
IReactorProcess.spawnProcess
. - Twisted matrix的所有内置功能,包括但不限于IReactorProcess.spawnProcess。
I'm personally currently using Gevent 1.0rc2 with Twisted 12.3 bridged by geventreactor
. I have implemented my own as-of-yet unpublished additions and enhancements to geventreactor
which I will publish soon, hopefully as part of geventreactor
's original GitHub repository: https://github.com/jyio/geventreactor.
我个人目前正在使用Gevent 1.0rc2和geventreactor之间的Twisted 12.3桥接。我已经为geventreactor实现了我自己尚未发布的添加和增强,我将很快发布它,希望作为geventreactor原始GitHub存储库的一部分:https://github.com/jyio/geventreactor。
My current layout allows me to program in the nice programming model of Gevent, and leverage things such as a non-blocking socket
, urllib2
and other modules. I can use regular Python code for doing regular things, as opposed to the learning curve and inconvenience of doing even simple, basic things the Twisted way. I can also easily use most 3rd party libraries that are normally either out of question with Twisted, or require the use of threads.
我现在的布局允许我在Gevent的良好编程模型中编程,并利用诸如非阻塞套接字、urllib2和其他模块之类的东西。我可以使用常规的Python代码来做常规的事情,而不是学习曲线和用扭曲的方式做简单的、基本的事情带来的不便。我还可以很容易地使用大多数第三方库,这些库通常在使用Twisted或者需要使用线程时都是不可能的。
I can also completely avoid the awkward and often overly complex callback based programming by using greenlets (instead of Deferred
s and callbacks, and/or @inlineCallbacks
).
我还可以通过使用greenlet(而不是延迟和回调,以及/或@inlineCallbacks)完全避免基于回调的笨拙和过于复杂的编程。
(This answer was written based on my personal experiences having used both Twisted and Gevent in real life projects, with significantly more experience using Twisted (but I don't claim to be a Twisted expert). The software I've had to write hasn't had to use too many of Twisted's features, so depending on the set of features you require of Twisted, the (relatively painless) extra complexity of mixing Gevent and Twisted might not be worth the trouble.)
(这个答案是基于我在现实生活中同时使用Twisted和Gevent的个人经验而写的,我使用Twisted和Gevent的经验要多得多(但我并不自称是Twisted expert)。我所编写的软件不必使用太多的Twisted的特性,所以根据您所需要的Twisted的特性集,混合Gevent和Twisted的额外复杂性可能是不值得的。
#1
202
"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design". If you are building something that is similar to a e-commerce site, then you should probably go with Django. It will get your work done quick. You dont have to worry about too many technology choices. It provides everything thing you need from template engine to ORM. It will be slightly opinionated about the way you structure your app, which is good If you ask me. And it has the strongest community of all the other libraries, which means easy help is available.
Django是一个高级的Python Web框架,它鼓励快速开发和干净、实用的设计。如果您正在构建类似于电子商务网站的东西,那么您应该使用Django。这会使你的工作很快完成。你不必担心太多的技术选择。它提供了从模板引擎到ORM所需的所有东西。如果你问我,它会对你的应用程序的结构有点固执己见。而且它拥有所有其他图书馆中最强大的社区,这意味着容易提供帮助。
"Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions". Beware - "microframework" may be misleading. This does not mean that Flask is a half-baked library. This mean the core of flask is very, very simple. Unlike Django, It will not make any Technology decisions for you. You are free to choose any template engine or ORM that pleases you. Even though it comes with Jinja template engine by default, you are always free to choose our own. As far as I know Flask comes in handy for writing APIs endpoints (RESTful services).
Flask是基于Werkzeug、Jinja 2和good intentions的Python微框架。当心——“微框架”可能具有误导性。这并不意味着烧瓶是一个不成熟的库。这意味着烧瓶的核心非常非常简单。与Django不同,它不会为您做任何技术决策。您可以*选择任何您喜欢的模板引擎或ORM。尽管Jinja模板引擎是默认的,但您始终可以*地选择我们自己的模板引擎。就我所知Flask对于编写api端点(RESTful服务)非常有用。
"Twisted is an event-driven networking engine written in python". This is a high-performance engine. The main reason for its speed is something called as deferred. Twisted is built on top of deferreds. For those of you who dont know about defereds, it is the mechanism through with asynchronous architecture is achieved. Twisted is very fast. But is not suitable for writing conventional webapps. If you want to do something low-level networking stuff, twisted is your friend.
Twisted matrix是一个用python编写的事件驱动的网络引擎。这是一台高性能的发动机。其速度的主要原因被称为延迟。扭曲是建立在延迟之上的。对于那些不了解延迟的人来说,实现异步架构的机制是可行的。扭曲的非常快。但不适合编写传统的网络应用程序。如果你想做一些低级的社交活动,twisted是你的朋友。
"Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user". Tornado stands some where between Django and Flask. If you want to write something with Django or Flask, but if you need a better performance, you can opt for Tornado. it can handle C10k problem very well if it is architected right.
Tornado是一个Python web框架和异步网络库,最初由FriendFeed开发。通过使用非阻塞的网络I/O, Tornado可扩展到数万个开放连接,对于长轮询、WebSockets和其他需要与每个用户建立长期连接的应用程序来说是理想的”。龙卷风在Django和Flask之间有一些。如果您想用Django或Flask编写一些内容,但是如果需要更好的性能,可以选择Tornado。如果体系结构正确,它可以很好地处理C10k问题。
"Cyclone is a web server framework for Python that implements the Tornado API as a Twisted protocol". Now, what if you want something that is nearly as performant as Twisted but easy to write conventional webapps? Say hello to cyclone. I would prefer Cyclone over Tornado. It has an API that is very similar to Tornado. As a matter of fact, this is a fork of Tornado. But the problem is it has relativly small community. Alexandre Fiori is the only main commiter to the repo.
“Cyclone是Python的web服务器框架,将Tornado API实现为Twisted protocol”。现在,如果你想要的是一款和传统的web应用程序一样的高性能,但又很容易编写的应用程序呢?向气旋问好。比起龙卷风,我更喜欢旋风。它有一个非常类似于龙卷风的API。事实上,这是龙卷风的一个分支。但问题是它的社区相对较小。亚历山大·菲奥里是“回购”的唯一主要参与者。
"Pyramid is a general, open source, Python web application development framework. Its primary goal is to make it easier for a Python developer to create web applications." I haven't really used Pyramid, but I went through the documentation. From what I understand, Pyramid is very similar to Flask and I think you can use Pyramid wherever Flask seems appropriate and vice-versa.
金字塔是一个通用的、开源的Python web应用程序开发框架。它的主要目标是使Python开发人员更容易创建web应用程序。我没有真正使用金字塔,但我浏览了文档。根据我的理解,金字塔和烧瓶非常相似,我认为你可以在烧瓶合适的地方使用金字塔,反之亦然。
EDIT: Request to review any other frameworks are welcomed!
编辑:欢迎评论任何其他框架!
来源:http://dhilipsiva.com/2013/05/19/python-libraries-django-twisted-tornado-flask-cyclone-and-pyramid.html
#2
55
This is obviously a somewhat biased answer, but that is not the same thing as a wrong answer; you should always use Twisted. I've answered similar questions before, but since your question is not quite the same, here are some reasons:
这显然是一个有偏见的回答,但这和错误的答案是不一样的;你应该经常使用Twisted。我之前也回答过类似的问题,但由于你的问题不太一样,以下是一些原因:
"Best Performance"
Twisted continuously monitors our performance at the speed.twistedmatrix.com website. We were also one of the first projects to be monitored by PyPy's similar site, thereby assuring the good performance of Twisted on the runtime that anyone concerned with high-performance applications in Python.
Twisted在网站上持续监控我们的性能。我们也是PyPy类似站点监视的首批项目之一,因此确保了所有关心Python中的高性能应用程序的人在运行时上的Twisted的良好性能。
"Scalability"
To my knowledge, none of the listed frameworks have any built-in support for automatic scaling; they're all communication frameworks, so you have to do the work to communicate between your scaling nodes. However, Twisted has an advantage in its built-in support for local multi-processing. In fairness, there is a third-party add-on for Tornado that allows you to do the same thing. In recent releases, Twisted has added features that increase the number of ways you can share work between cores, and work is ongoing in that area. Twisted also has a couple of well-integrated, "native" RPC protocols which offer a construction-kit for whatever scaling idiom you want to pursue.
据我所知,所有列出的框架都不支持自动伸缩;它们都是通信框架,所以您必须在伸缩节点之间进行通信。然而,Twisted在内置支持本地多处理方面有优势。公平地说,Tornado支持第三方插件允许你做同样的事情。在最近的版本中,Twisted增加了一些特性,增加了在核心之间共享工作的方式,并且在这方面还在进行工作。Twisted还提供了一些集成良好的“原生”RPC协议,它们为您所追求的任何扩展习惯提供了构造工具包。
"Most Useful"
Lots of people seem to find Twisted very useful. So much so that many of them have extended it and made their extensions available to you.
很多人似乎觉得Twisted真的很有用。如此之多以至于他们中的许多人已经扩展了它并且使他们的扩展对你可用。
"Functionality"
Out of the box, Twisted includes:
Out of the box, Twisted includes:
- good support for test-driven development of all the following
- 对以下所有测试驱动开发的良好支持
- TCP servers, clients, transport layer security
- TCP服务器、客户端、传输层安全
- SSH client and server
- SSH客户机和服务器
- IMAP4, ESMTP, POP3 clients and servers
- IMAP4, ESMTP, POP3客户端和服务器
- DNS client and server
- DNS客户机和服务器
- HTTP client and server
- HTTP客户机和服务器
- IRC, XMPP, OSCAR, MSN clients and servers
- IRC, XMPP, OSCAR, MSN客户端和服务器
In this last department, at least, Twisted seems a clear winner for built-in functionality. And all this, in a package just over 2 megabytes!
至少在这最后一个部门中,Twisted matrix显然是内置功能的赢家。所有这些,在一个超过2兆字节的包里!
#3
46
I like @Glyph response. Twisted is very comprehensive, rich python framework. Twisted and Tornado have a very similar design. And I like this design very much:
我喜欢@Glyph响应。Twisted matrix是一个非常全面、丰富的python框架。Twisted和Tornado则有着非常相似的设计。我非常喜欢这个设计:
- it's fast
- 它的速度非常快
- easy to understand
- 容易理解的
- easy to extend
- 容易扩展
- doesn't require c-extensions
- 不需要c扩展
- works on PyPy.
- PyPy工作。
But I want to highlight Tornado, which I prefer and recently gain popularity. Tornado, like Twisted, uses callback style programming, but it can be inlined using tornado.gen.engine
(twisted.internet.inlineCallbacks
in Twisted).
但是我想强调龙卷风,我喜欢它,最近它流行起来了。Tornado和Twisted一样,使用回调样式编程,但可以使用Tornado .gen内联。引擎(twisted.internet.inlineCallbacks扭曲)。
Codebase
The best comment is from http://cyclone.io site. cyclone tries to mix Twisted and Tornado because:
最好的评论来自http://cyclone。io网站。旋风试图混合扭曲和龙卷风,因为:
Twisted is one of the most mature libraries for non-blocking I/O available to the public. Tornado is the open source version of FriendFeed’s web server, one of the most popular and fast web servers for Python, with a very decent API for building web applications.
Twisted matrix是面向公众的最成熟的非阻塞I/O库之一。Tornado是FriendFeed web服务器的开源版本,它是Python最流行、速度最快的web服务器之一,具有非常好的用于构建web应用程序的API。
The idea is to bridge Tornado's elegant and straightforward API to Twisted's Event-Loop, enabling a vast number of supported protocols.
其想法是将Tornado优雅而直接的API与Twisted的事件循环连接起来,从而支持大量受支持的协议。
But in 2011 tornado.platform.twisted
was out which brings similar functionality.
但在2011年tornado.platform。twisted matrix也推出了类似的功能。
Performance
Tornado has much better performance. It also works seamlessly with PyPy, and get huge gain.
Tornado有更好的表现。它还可以与PyPy无缝地工作,并获得巨大的收益。
Scalability
The same like Twisted. Tornado has tornado.process
and a lot of rpc services implemented on top of it.
同样的像扭曲。龙卷风有龙卷风。流程和许多在其之上实现的rpc服务。
Functionality
There are 71 Tornado based package, compared to 148 Twisted's and 48 Gevent's. But if you look carefully and compute median of packages upload time, you will see that Twisted ones are the oldest, then Gevent and Tornado the freshest. Furthermore there is tornado.platform.twisted
module which allows you to run code written for Twisted on Tornado.
总共有71个龙卷风包,而只有148个Twisted和48个Gevent。但是如果你仔细观察并计算出包上传时间的中值,你会发现扭曲的是最古老的,然后是Gevent和龙卷风最新鲜的。此外还有tornado.platform。twisted模块,它允许你运行被写在龙卷风上的代码。
Summary
With Tornado you can use a code from Twisted. There is no need to use cyclone which only twists your code (your code becomes more messy).
使用Tornado,你可以使用来自Twisted的代码。没有必要使用只有扭曲代码的旋风(您的代码变得更加混乱)。
As for 2014, Tornado is considered as widely accepted and default async framework which works both on python2 and python3. Also the latest version 4.x brings a lot of functionality from https://docs.python.org/dev/library/asyncio.html.
2014年,Tornado被认为是广泛接受的默认异步框架,可以在python2和python3上工作。也是最新的版本4。x从https://docs.python.org/dev/library/asyncio.html提供了很多功能。
I wrote an article, explaining why I consider that Tornado - the best Python web framework where I wrote much more about Tornado functionality.
我写了一篇文章,解释为什么我认为龙卷风是最好的Python web框架,在那里我写了更多关于龙卷风的功能。
#4
14
(UPDATE: I'm sadly surprised about how few answers here recommend or even mention Gevent—I don't think it's in proportion to the popularity, performance and ease of use of this excellent library!)
(更新:我很遗憾地感到惊讶的是,这里的答案很少,甚至很少提到gevent——我不认为它与这个优秀的库的受欢迎程度、性能和易用性成正比!)
Gevent and Twisted are not mutually exclusive, even though the contrary might seem obvious at first. There is a project called geventreactor
which allows one to relatively smoothly leverage the best of both worlds, namely:
Gevent和Twisted并不是相互排斥的,尽管相反的情况一开始看起来是显而易见的。有一个项目叫做geventreactor,它允许我们相对平稳地利用这两个方面的优点,即:
- The efficient and cheap (cooperative green) thread model of Gevent, which is much easier to program in when it comes to concurrency—frankly, Twisted's
inlineCallbacks
is simply not up to the job in terms of performance when it comes to many coroutines, and neither in terms of ease/transparency of use:yield
andDeferreds
everywhere; often hard to build some abstractions; horrifyingly useless stack traces with both bareDeferred
s as well as, and even more so with@inlineCallbacks
. - 有效和廉价的(绿色)合作Gevent的线程模型,这是更容易在谈到concurrency-frankly程序,扭曲的inlineCallbacks不胜任这项工作的性能在许多协同程序,也在缓解/使用透明度:产量和递延无处不在;通常很难建立一些抽象;令人毛骨悚然的无用的堆叠痕迹,既有简单的延迟,也有@inlineCallbacks。
- All the built-in functionality of Twisted you can ever dream of, including but not limited to
IReactorProcess.spawnProcess
. - Twisted matrix的所有内置功能,包括但不限于IReactorProcess.spawnProcess。
I'm personally currently using Gevent 1.0rc2 with Twisted 12.3 bridged by geventreactor
. I have implemented my own as-of-yet unpublished additions and enhancements to geventreactor
which I will publish soon, hopefully as part of geventreactor
's original GitHub repository: https://github.com/jyio/geventreactor.
我个人目前正在使用Gevent 1.0rc2和geventreactor之间的Twisted 12.3桥接。我已经为geventreactor实现了我自己尚未发布的添加和增强,我将很快发布它,希望作为geventreactor原始GitHub存储库的一部分:https://github.com/jyio/geventreactor。
My current layout allows me to program in the nice programming model of Gevent, and leverage things such as a non-blocking socket
, urllib2
and other modules. I can use regular Python code for doing regular things, as opposed to the learning curve and inconvenience of doing even simple, basic things the Twisted way. I can also easily use most 3rd party libraries that are normally either out of question with Twisted, or require the use of threads.
我现在的布局允许我在Gevent的良好编程模型中编程,并利用诸如非阻塞套接字、urllib2和其他模块之类的东西。我可以使用常规的Python代码来做常规的事情,而不是学习曲线和用扭曲的方式做简单的、基本的事情带来的不便。我还可以很容易地使用大多数第三方库,这些库通常在使用Twisted或者需要使用线程时都是不可能的。
I can also completely avoid the awkward and often overly complex callback based programming by using greenlets (instead of Deferred
s and callbacks, and/or @inlineCallbacks
).
我还可以通过使用greenlet(而不是延迟和回调,以及/或@inlineCallbacks)完全避免基于回调的笨拙和过于复杂的编程。
(This answer was written based on my personal experiences having used both Twisted and Gevent in real life projects, with significantly more experience using Twisted (but I don't claim to be a Twisted expert). The software I've had to write hasn't had to use too many of Twisted's features, so depending on the set of features you require of Twisted, the (relatively painless) extra complexity of mixing Gevent and Twisted might not be worth the trouble.)
(这个答案是基于我在现实生活中同时使用Twisted和Gevent的个人经验而写的,我使用Twisted和Gevent的经验要多得多(但我并不自称是Twisted expert)。我所编写的软件不必使用太多的Twisted的特性,所以根据您所需要的Twisted的特性集,混合Gevent和Twisted的额外复杂性可能是不值得的。