When and how to use Tornado? When is it useless?

29,266

Solution 1

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

This distinction is a bit blurry. If you are only serving static pages, you would use one of the fast servers like lighthttpd. Otherwise, most servers provide a varying complexity of framework to develop web applications. 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 and Twisted are frameworks that provide support non-blocking, asynchronous web / networking application development.

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

By its very nature, Async / Non-Blocking I/O works great when it is I/O intensive and not computation intensive. Most web / networking applications suits well for this model. 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. While Tornado / Twisted can do the job of web server, responding to web requests.

How can we make inefficient site using Tornado?

  1. Do any thing computational intensive task
  2. 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.

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.

Tornado and Twisted provide reasonable performance and they are good for building performant web applications. You can check out the testimonials for both twisted and tornado to see what they are capable of.

Solution 2

I'm sorry for answering an old question, but I came across this one and wondered why it didn't have more answers. To answer Bart J's question:

I would like to parse RSS feeds in the Tornado application. Would you consider that fairly computationally intensive?

Well that depends on what kind of parsing you're doing and on what hardware :) Long time is a long time, so if your app takes more than say half a second to respond, it'll seem sluggish - profile your app.

The key to fast systems is great architecture, not so much the specifics as for instance which framework you're using (Twisted, Tornado, Apache+PHP). Tornado has an asynchronous processing style and that's really what a lot of it comes down to in my opinion. Node.js, Twisted and Yaws are examples of other asynchronous web servers that scale very well because of a lightweight approach and asynchronous processing style.

So:

When should Tornado be used?

When is it useless?

Tornado is good for handling a lot of connections, since it can respond to an incoming client, dispatch a request handler and don't think about that client until the result-callback is pushed on the event queue. So for that specific quality Tornado should be used when you want to scale well when handling a lot of requests. The async processing facilitates functional decoupling and shared-nothing data access. That swings really well with stateless design like REST or other Service Oriented Architectures. You also don't have to deal with spawning threads or processes with the inherent overhead so much and you can save some of the locking/IPC trouble.

Tornado won't make much of a difference, on the other hand, if your backend and/or data store takes a long time to process the requests. It helps to do concurrent designs and Web services in particular. The concurrent architecture makes it easier to scale your design and keep the coupling low. That's my experience with Tornado at least.

Share:
29,266
Vladimir Sidorenko
Author by

Vladimir Sidorenko

I lead a team of web developers. Gearheart.io is a competent web development team. Since 2012, we have been providing top quality services to clients all over the world including USA, EU, and Israel. We work closely with our clients to understand their requirements and provide a myriad of services including product idea elicitation, custom web applications development, MVP specification and development, single page applications, APIs for mobile apps, and much more. Our competency stems from our experience. All members of Gearheart.io enjoy extensive experience in the field of web development and technology. Each developer has more than 3 years of experience with Django and Angular. Our work is aided by state of the art tools and methodologies in web development. Furthermore, to stay on top of our game, we value knowledge and growth above all and regularly take learning sessions to ensure our solutions and expertise are polished and updated. The clients of Gearheart.io benefit from having a reliable team on their side that offers the best, most advanced solutions in web development. We strive to work directly with clients in the most friendly and understanding manner so any requirements our clients have are easily taken into consideration. Get in touch with us today for more information. Main tools: Python, Django, Angular.js, React.js, Solr. Specialization: Web app development, Django development, Angular.js development, Single Page Applications (SPA), Custom web app development, Outsourcing, Project management, Testing, mobile API development, Planning.

Updated on April 12, 2020

Comments

  • Vladimir Sidorenko
    Vladimir Sidorenko about 4 years

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

    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.

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

    • When should Tornado be used?
    • When is it useless?
    • When using it, what should be taken into account?
    • How can we make inefficient site using Tornado?
    • There is a server and a webframework. When should we use framework and when can we replace it with other one?
  • Vladimir Sidorenko
    Vladimir Sidorenko over 13 years
    Thank you for the answer. Just want to make some points clear: Can I use Flask or Django bihind Tornado and get all of it's benefits (if I don't make any camputational tasks) without changing the code of application?
  • Vladimir Sidorenko
    Vladimir Sidorenko over 13 years
    If yes - what will be the difference compared to running say with flup? Thank you.
  • Susheel Javadi
    Susheel Javadi over 13 years
    I would like to parse RSS feeds in the Tornado application. Would you consider that fairly computationally intensive?
  • tigeronk2
    tigeronk2 over 11 years
    What if you do have few operations in your service that are computationally intensive(say >1sec)? Is it still possible to do that kind of processing in a non-blocking manner?
  • Morten Jensen
    Morten Jensen over 11 years
    @tigeronk2 Yes, but you will have to run the computation in another thread/process.
  • Tyeth
    Tyeth almost 6 years
    Or potentially run the intensive process as another service to achieve scalability and separation with a small overhead compared to managing another process. Look at the Service oriented architectures link.
  • tripleee
    tripleee over 5 years
    Parsing RSS is almost by definition not heavy processing, unless you are doing it very very wrong.