#34359: Support disabling global thread_sensitive flag for Async ORM
-----------------------------------------+------------------------
               Reporter:  Jameel A.      |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Uncategorized  |        Version:  4.1
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 Apologies if this has been discussed before, but I couldn't find a related
 issue.

 The way the Async ORM interface is currently implemented is by simply
 introducing new `a`-prefixed methods that wrap the original `QuerySet`
 methods in `sync_to_async`. On the surface this is a simple, slightly
 suboptimal, way of implementing `asyncio` support.

 Under the surface, though, there be dragons. With `asgiref` enabling the
 `thread_sensitive` by default, what actually happens is ''ALL'' uses of
 `sync_to_async` get queued onto a single thread. This can have disastrous
 performance implications as we've seen in production (especially when used
 with native `async` code).

 While `thread_sensitive` is ''safer'' as mentioned in the docs, it's not
 always necessary. For example, when using Postgres, the `psycopg` database
 driver is thread-safe and appears to work fine with the `thread_sensitive`
 flag disabled.

 The issue here is not whether `thread_sensitive` should be `True` by
 default, but rather there should be a way to disable it when the user
 ''knows'' it's safe to do so. In particular, for the async ORM and async
 cache interfaces, it would be wonderful to configure thread sensitivity
 via a setting.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34359>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018672e6e6e1-059fbb2a-a6cb-481f-b5d6-7b8df62fbd3b-000000%40eu-central-1.amazonses.com.

Reply via email to