Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disadvantages of using ASGI instead of WSGI [closed]

What is the explicit and clear disadvantages of using ASGI instead of WSGI for HTTP request handling in Django in general?

I know ASGI is for asynchronous tasks, but it can also handle synchronous HTTP requests via http.* channels. Is it slower than normal WSGI or is there any unsupported features comparing to WSGI?

One more, to provide both REST API and websocket handling in same project, which way do you prefer and why?

  1. WSGI for REST + ASGI for websocket in different server instances
  2. WSGI for REST + ASGI for websocket in same machine
  3. ASGI for both
like image 379
Analysis Avatar asked Sep 24 '17 04:09

Analysis


People also ask

Which is better WSGI or ASGI?

ASGI is a spiritual successor to WSGI, the long-standing Python standard for compatibility between web servers, frameworks, and applications. WSGI succeeded in allowing much more freedom and innovation in the Python web space, and ASGI's goal is to continue this onward into the land of asynchronous Python.

Does Django use WSGI or ASGI?

As well as WSGI, Django also supports deploying on ASGI, the emerging Python standard for asynchronous web servers and applications.

Does flask support ASGI?

Quart: While the staple Python web framework Flask does support ASGI, Flask is not designed from the inside out to take advantage of async metaphors. Quart, from GitLab, uses Flask's syntax and metaphors, but allows async route handlers.

How does ASGI work?

ASGI consists of two different components: A protocol server, which terminates sockets and translates them into connections and per-connection event messages. An application, which lives inside a protocol server, is instanciated once per connection, and handles event messages as they happen.


2 Answers

I think the one major downside you will find is that the ASGI servers are newer and therefore tested less, may have less features, fewer in number, and probably have a smaller community behind them. However, I use an ASGI server (Daphne) for everything and feel that websockets offer so much in terms of user experience that everything will eventually shift to ASGI.

Being able to use asyncio in your code is a major benefit for web programming. Instead of running 10 queries one after the other and waiting for each one to come back, you can run 10 queries at the same time, while hitting your cache and making a HTTP request simultaneously on a single thread.

like image 111
kagronick Avatar answered Oct 07 '22 21:10

kagronick


I didn't do any benchmarking but use both WSGI and ASGI in several project and didn't see any sufficient differences between their performance, so if the Django WSGI performance is acceptable for you then ASGI will work too.

For the REST + websockets API I used ASGI for both. There is no reason to use WSGI if you have ASGI enabled in your project (WSGI works over ASGI).

like image 26
stasdavydov Avatar answered Oct 07 '22 20:10

stasdavydov