Performance: ASGI vs WSGI
HIGH IMPACT
This affects how quickly a Django app can respond to requests and handle multiple users at once.
import asyncio from django.core.asgi import get_asgi_application async def application(scope, receive, send): # ASGI asynchronous app await send({ 'type': 'http.response.start', 'status': 200, 'headers': [(b'content-type', b'text/plain')], }) await send({ 'type': 'http.response.body', 'body': b'Hello World', })
def application(environ, start_response): # WSGI synchronous app response_body = 'Hello World' start_response('200 OK', [('Content-Type', 'text/plain')]) return [response_body.encode('utf-8')]
| Pattern | Concurrency | Blocking Behavior | Latency Under Load | Verdict |
|---|---|---|---|---|
| WSGI (Synchronous) | Single request per worker | Blocks on each request | High latency with many users | [X] Bad |
| ASGI (Asynchronous) | Multiple concurrent requests | Non-blocking async handling | Low latency even under load | [OK] Good |