Hi folks,
I recently started experimenting with asynchronous views on an existing codebase to improve response times where the view rendering depends on the results of dozens of database queries.
I’m past optimizing the database queries themselves and the logical next step was to try executing (at least some of) them concurrently.
So I’ve switched to Daphne ASGI server and started adding async views and making database queries concurrently using await asyncio.gather(....)
.
However when I look at the query execution timeline in Sentry, the database queries appear to happen strictly sequentially.
I understand that asynchronous does not necessary mean concurrent but I was hoping that Django + ASGI will bring both. I also re-read the relevant documentation here but I am left clueless: Asynchronous support | Django documentation | Django
I’m using psycopg2-binary = "^2.9.6"
with django = "^4.2"
.
Any insights would be welcome.
Cheers,
Márton