Postgresql – Why aren’t read-only queries executing concurrently?

concurrencydjangopostgresqlsqlite

I have a Django app using either sqlite or Postgres. (I've tried both and encountered the same problem.) Requesting a particular endpoint results in a read-only query like this that takes 1.5-3 seconds before the response.

The problem occurs when Django receives simultaneous requests to this endpoint, which is common in my application. I expect Django to process the requests in parallel and still return a response in 3-4 seconds. Instead, I get no response for any of the queries until 9-12 seconds. In know that Django supports concurrent requests, so I suspect this is a database issue.

What am I missing?

Best Answer

The problem is that I was using Django's built-in development server (runserver). The problem goes away using Gunicorn. It doesn't matter if the database backend is Sqlite or Postgres.