Need advice about which tool to choose?Ask the StackShare community!

asyncio

111
157
+ 1
13
Tornado

435
407
+ 1
167
Add tool

Tornado vs asyncio: What are the differences?

Introduction

In this article, we will explore the key differences between Tornado and asyncio, two popular frameworks used for asynchronous programming in Python.

  1. Execution Model: Tornado is an event-driven framework, while asyncio is based on coroutines. Tornado uses an event loop to manage events and callbacks, allowing it to handle a large number of simultaneous connections efficiently. On the other hand, asyncio employs coroutines, which are lightweight functions that can be paused and resumed, to achieve asynchronous execution.

  2. Compatibility: Tornado is compatible with both Python 2 and Python 3, making it suitable for a wider range of projects. asyncio, on the other hand, is specifically designed for Python 3.4 and above, taking advantage of the language improvements introduced in later versions.

  3. Code Structure: Tornado follows a more traditional approach with explicit callbacks and the use of decorator-based syntax for defining request handlers. It provides a comprehensive set of features for building web applications, including routing, template rendering, and WebSocket support. asyncio, on the other hand, provides a more lightweight and flexible framework for asynchronous programming, allowing developers to create custom event loops and use coroutines in a more modular manner.

  4. Community and Support: Tornado has been around for a longer time and has a larger community of users and contributors. It has been extensively used in production environments and has a well-documented API. asyncio, being a relatively newer framework, is still evolving and may have fewer third-party libraries and resources available.

  5. Concurrency Models: Tornado uses a single-threaded, non-blocking I/O approach to achieve high concurrency. It achieves this by using asynchronous networking and non-blocking file I/O operations. asyncio, on the other hand, provides a more granular control over concurrency through the use of coroutines and can handle more complex concurrency patterns, such as concurrent HTTP requests.

In summary, the key differences between Tornado and asyncio lie in their execution models, compatibility, code structure, community support, and concurrency models. These differences make them suitable for different types of projects and use cases.

Advice on asyncio and Tornado
aryan patel
Python Developer at Fyers Securities · | 1 upvotes · 3.4K views
Needs advice
on
asyncioasyncioRedisRedis
and
TornadoTornado
in

I want to use Redis non-blocking with Tornado. How I should use the Redis code using tornadis to achieve max number of connections. I had used the tornadis and with WebSocket handler, I inherited the Redis based pub/sub client inside a class and in the main loop we created the instance of a class. but it decreases the numbr of connections with a huge amount. how we should configure?

See more
Replies (1)
Attila Fulop
Management Advisor at artkonekt · | 3 upvotes · 2.4K views
Recommends
on
RedisRedis

If there is a way to connect to Redis via UNIX sockets instead of TCP then it worth it to switch over. We had a busy e-commerce site with heavy Redis usage and we saw a 4-5x(!) performance improvement during testing situations with a high number of concurrent requests.

I know that the probability these days is rather low to have such a scenario where you have Redis and the app on the same host (and thus the ability to connect over UNIX sockets). But if that's the case, it's definitely worth it.

See more
Get Advice from developers at your company using StackShare Enterprise. Sign up for StackShare Enterprise.
Learn More
Pros of asyncio
Pros of Tornado
  • 4
    Cooperative Multitasking
  • 4
    I/O Wait
  • 3
    Network Call
  • 2
    I/O bound computation
  • 37
    Open source
  • 31
    So fast
  • 27
    Great for microservices architecture
  • 20
    Websockets
  • 17
    Simple
  • 14
    Asynchronous
  • 11
    Python
  • 7
    Lightweight
  • 3
    Handles well persistent connexions

Sign up to add or upvote prosMake informed product decisions

Cons of asyncio
Cons of Tornado
    Be the first to leave a con
    • 2
      Event loop is complicated

    Sign up to add or upvote consMake informed product decisions

    - No public GitHub repository available -

    What is asyncio?

    This module provides infrastructure for writing single-threaded concurrent code using coroutines, multiplexing I/O access over sockets and other resources, running network clients and servers, and other related primitives.

    What is Tornado?

    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.

    Need advice about which tool to choose?Ask the StackShare community!

    Jobs that mention asyncio and Tornado as a desired skillset
    What companies use asyncio?
    What companies use Tornado?
    See which teams inside your own company are using asyncio or Tornado.
    Sign up for StackShare EnterpriseLearn More

    Sign up to get full access to all the companiesMake informed product decisions

    What tools integrate with asyncio?
    What tools integrate with Tornado?

    Sign up to get full access to all the tool integrationsMake informed product decisions

    Blog Posts

    JavaScriptPythonPubNub+4
    7
    1501
    What are some alternatives to asyncio and Tornado?
    Flask
    Flask is intended for getting started very quickly and was developed with best intentions in mind.
    Celery
    Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.
    gevent
    It is a coroutine -based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libev or libuv event loop.
    Node.js
    Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
    Twisted
    Twisted is an event-driven networking engine written in Python and licensed under the open source ​MIT license. Twisted runs on Python 2 and an ever growing subset also works with Python 3. Twisted also supports many common network protocols, including SMTP, POP3, IMAP, SSHv2, and DNS.
    See all alternatives