Pulpcode

捕获,搅碎,拼接,吞咽

0%

什么时候使用tornado

初学tornado的我,曾经一直好奇tornado到底适合什么样的开发,stackoverflow的一个提问曾经给了我解答。

问题部分:

Ok, Tornado is non-blocking and quite fast and it can handle a lot of standing requests easily.

好吧,tornado是一个非阻塞的而且可以快速的处理大量并发请求。

But I guess it’s not a silver bullet and if we just blindly run Django-based or any other site with Tornado it won’t give any performance boost.

但是我猜测它并非银弹,并且如果我们把其他的web站点,类似django这样的运行在tornado上,并不会提升效率

I couldn’t find comprehensive explanation of this, so I’m asking it here:

我不能得到一个全面的解释,所以我在这里这样提问。

When should Tornado be used?

什么时候应当使用tornado

When is it useless?

什么时候使用tornado并没有效果。

When using it, what should be taken into account?

当使用它的时候,还有什么其它因素需要考虑。

How can we make inefficient site using Tornado?

我们什么样的使用方式会使tornado的效率低下。

There is a server and a webframework. When should we use framework and when can we replace it with other one?

tornado既是一个服务器,又是一个web框架,什么时候我们要使用这个框架,什么时候我们需要用别的框架替换它?


回答(对问题部分一一解答)

There is a server and a webframework. When should we use framework and when can we replace it with other one?

这里有一个服务器和一个web框架,什么时候我们要使用这个框架,什么时候我们需要用别的框架替换它?

This distinction is a bit blurry.

这个差异有些模糊。

Only if you are serving static pages, you would use one of the fast server like lighthttpd.

如果你的服务就是静态页面,那么你可以简单的使用一个快速的服务器,比如lighttpd。

Other wise, most servers provides a varying complexity of framework to develop web applications.

否则,大多数服务器为应用程序提供非常复杂的web框架。

Tornado is a good web framework. Twisted is even more capable and is considered a good networking framework. It has support for lot of protocols.

tornado是一个好的web框架,twisted甚至被认为是一个更有能力的web框架。它支持很多协议。

Tornado and Twisted are frameworks that provide support non-blocking, asynchronous web / networking application development.

tornado和twisted作为一个框架支持异步非阻塞的web应用。


When should Tornado be used? When is it useless? When using it, what should be taken into account?

什么时候使用tornado才是有效的,什么时候使用tornado是无效的?当我使用它的时候,还有哪些其他的因素需要被考虑。

By it’s very nature, Async / Non-Blocking I/O works great when it is I/O intensive and not computation intensive.

就其本质而言,异步非存储模型非常适合IO密集型而非CPU密集型的任务。

Most web / networking applications suits well for this model.

对于大多数web和网络应用而言,本身就非常适合此模式。

If your application demands certain computational intensive task to be done then it has to be delegated to some other service that can handle it better.

如果你的程序确切无疑是要完成CPU密集型任务,把这个请求委托给其它服务器能处理的更好。

While Tornado / Twisted can do the job of web server, responding to web requests.

这样tornado和twisted共存于服务器,响应web请求。


How can we make inefficient site using Tornado?

什么样的方式使用tornado是错误的,会使我的网站效率下降。

Do any thing computational intensive task

做任何计算密集型的任务。

Introduce blocking operations

任何阻塞操作。


But I guess it’s not a silver bullet and if we just blindly run Django-based or any other site with Tornado it won’t give any performance boost.

但是我猜测它并非银弹,并且如果我们把其他的web站点,类似django这样的运行在tornado上,并不会有任何的效率提升。

Performance is usually a characteristic of complete web application architecture. You can bring down the performance with most web frameworks, if the application is not designed properly. Think about caching, load balancing etc.

性能一般而言仅仅是web应用的特征之一,你可以完全不去理会web框架带来的性能,如果你的程序性能不佳,想象缓存,或者负载均衡。

Tornado and Twisted provides reasonable performance and is good for building a very performant web application. You can check out the testimonials for both twisted and tornado to see what they are capable of.

tornado和twisted提供合理的性能提升。并且非常适合构建高性能web应用。你可以查查它们的测试鉴定,看看他们表现的怎么样。