About The Performance of ASGI Compared to WSGI
Analogous WSGI and ASGI views might take the same time to return a response when handled individually. The difference becomes apparent with multiple concurrent visitors.
Let’s assume it takes 1 second to load data from PostgreSQL, render, and return a home page for a single visitor. Now consider 100 visitors arriving at the same time.
WSGI with 10 worker threads:
- Only 10 requests are handled concurrently, while the remaining 90 are queued.
- Each batch of 10 requests takes 1 second to process.
- The last requests in the queue may take up to 10 seconds to receive a response.
ASGI with 1 worker using asynchronous operations:
- All 100 requests are initiated concurrently. Each request "awaits" the PostgreSQL query without blocking the event loop.
- All responses are served within the same 1 second, provided PostgreSQL is configured to handle 100 concurrent queries (default
max_connectionsvalue).
Tips and Tricks Programming Dev Ops Architecture Django 5.2 Django 4.2 Django 3.2 Gunicorn ASGI WSGI NGINX Unit Uvicorn Daphne Hypercorn
Django/Python Consulting
If you have a specific Django challenge or integration you'd like to solve, I'd be happy to help. Book a free 30-minute call to discuss your project, see if we're a good fit, and explore the best approach for your needs. After the call, you'll receive a tailored cost estimate based on what we discuss.
Also by me
Django Messaging
For Django-based social platforms.
Django Paddle Subscriptions
For Django-based SaaS projects.
Django GDPR Cookie Consent
For Django websites that use cookies.