Hi Jonathan,

Daphne runs a single asyncio event loop in the main thread which services
all protocol handling (low-level HTTP and websocket) and Channels-level
async-native code (ASGI middleware, routing, async consumers). Any
synchronous calls (e.g. methods on synchronous consumers) are queued up to
run in a threadpool with NUM_CPUS * 5 threads by default.

It's quite different from the thread-handling-one-request model. This isn't
the right venue for a complete explanation of how Python async works in
combination with the GIL, unfortunately - hopefully you can find that
elsewhere if you are interested.

Andrew

On Tue, Mar 20, 2018 at 2:30 PM, Jonathan Stray <[email protected]>
wrote:

> Can anyone offer a brief account of how Channels uses threads to service
> multiple requests?
>
> My understanding is that there are multiple workers, and I imagine each is
> a thread which can handle one request (Django view-style request) at a
> time. Is this correct? I also don't quite understand how this is possible
> in one Python process given the Global Interpreter Lock.
>
> Basically I am trying to reason about race conditions and scaling, and I
> don't have enough understanding to do it.
>
> Apologies if this is document elsewhere, but I've so far not been able to
> find it.
>
>   - Jonathan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-developers/b2da063e-0fa0-4f35-a86d-
> 536fe210f1b2%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/b2da063e-0fa0-4f35-a86d-536fe210f1b2%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAFwN1ureEnSoCYFfON%3DpbWh530GiW4o6NVbS8ugnwPnMOceuMA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to