[Django]-How does Django handle multiple requests?

28👍

Django handles just a request at a time.

If you use the very old CGI interface (between your web-server and Django), a new Django process is started at every request. But I think nobody do this.

There are many additional interfaces on web servers, not do load at every request a new server side program. FastCGI is one of these (agnostic to programming language), some programs have own module directly implemented in web server (e.g. mod-php) [python had this in the past]. But now Django and in general python, prefer WSGI interface.

So webserver open one or more programs (Django app) in parallel. The web server will send request to a free process (or it queue requests, this is handled by web server). How many processes, and for how long, it depend on web server configuration.

The databases supported by django supports concurrency, so there is no problem on having different processes handling the same app. [SQLite is different, but you should use this, just for developing/testing Django]. By writing to some log files [usually multiline], one could see some problems (parallel process which write at the same time, the same file).

NOTE: in such explanation I use “web server” in a broad sense. This includes gunicorn, mod-wsgi etc.

Leave a comment