'How to use the power of uvicorn and asgi in django?
I implemented a tiny Django app (v4.0.4) containing a REST API — GET method for retrieving some data. Next, I wanted to run the project using gunicorn+uvicorn since I saw a more benchmark performance than a normal deployment in an article. So I decided to get my own benchmark using wrk tool.
Here's what I've got:
| Command | Webserver | Protocol | Result (Req/Sec) |
|---|---|---|---|
python manage.py runserver 0.0.0.0:8000 |
Django Default | wsgi | 13.06 |
gunicorn bitpin.wsgi:application --bind 0.0.0.0:8000 -w 2 |
gunicorn | wsgi | 45.20 |
gunicorn bitpin.asgi:application --bind 0.0.0.0:8000 -w 2 -k uvicorn.workers.UvicornWorker |
uvicorn+gunicorn | asgi | 22.17 |
However, the above result demonstrates something else!
Is the reason that when I want to use asgi I have to use async method instead for my API view? If so how can I change a Django REST API view to an async one?
Or might I've missed some configurations?
[NOTE]:
I ran the benchmark using the following command:
wrk -t4 -c11 -d20s -H "Authorization: Token xxx" http://127.0.0.1:8000/api/v1/content/It is worth mentioning that for this test I used two workers for
gunicornand it is obvious that the higher workers, the better the performance will be.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
