[Django]-Django and Channels and ASGI Thread Problem

4👍

For synchronous requests Channels makes a ThreadPool. If it ran HTTP requests in the event loop every database query and cache hit would lock up the event loop.

If you do not set the environment variable ASGI_THREADS it uses the default set by concurrent.futures.ThreadPool which IMO is way too high as it is the number of CPU cores multiplied by 5. Set ASGI_THREADS to a lower number and use multiple Daphne processes. By using a lower number of threads and multiple processes you avoid some of the slowdown caused by Python’s global interpreter lock.

Leave a comment