#30451: Add ASGI support to Django.
-------------------------------+-----------------------------------------
     Reporter:  Andrew Godwin  |                    Owner:  Andrew Godwin
         Type:  New feature    |                   Status:  assigned
    Component:  HTTP handling  |                  Version:  master
     Severity:  Normal         |               Resolution:
     Keywords:  asgi           |             Triage Stage:  Accepted
    Has patch:  1              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+-----------------------------------------

Comment (by Ran Benita):

 It looks like the patch is going to be merged. I feel like I should at
 least point out some downsides before this step is taken. (Note, I am not
 a Django dev, just a user).

 The patch adds an unconditional asyncio import. It is quite heavy for
 something most users won't use at least initially. On my aging laptop:

 - Import time: 50ms
 - Memory usage: ~5MB

 Command for import time: `python3.7 -X importtime -c 'import asyncio' |&
 tail -1`

 Script for memory usage:

 {{{
 #!python
 from resource import getrusage, RUSAGE_SELF

 before = getrusage(RUSAGE_SELF)
 import asyncio
 after = getrusage(RUSAGE_SELF)

 print(f'{after.ru_maxrss - before.ru_maxrss}kb')
 }}}

 The patch adds 2 dependencies, one direct `asgiref` and one transitive
 `async_timeout`.

 The patch implements the ASGI specification, but that specification has
 not been adopted widely yet and has not been proposed for official status
 (that I know of) like WSGI has.

 ASGI depends on asyncio, but there are other alternatives worth
 considering (like trio and curio). And of course there is gevent which has
 been used successfully by many companies (including mine) for async Djagno
 for some time.

 The patch on its own will run all views in a thread pool
 (asgiref.sync_to_async -> loop.run_in_executor -> default
 ThreadPoolExecutor). The default number of workers used is the number of
 cores * 5, so for example an 8 core will use 40 workers. If postgresql is
 used with persistent connections, this is a hazard since postgresql
 doesn't like this many connections. So users will need to use a connection
 pool, or disable persistent connections.

 In my opinion, it would be hasty be merge ASGI support before the overall
 plan is decided. If a DEP is later proposed, and rejected (I hope not!),
 will it still make sense to have merged this?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30451#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.bc629868d91b289a3360a4343a0a25ae%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to