#35853: Disable garbage collection during transaction.atomic.
-------------------------------------+-------------------------------------
     Reporter:  Matej Spiller Muys   |                    Owner:  (none)
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  5.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:  gc, atomic,          |             Triage Stage:
  transaction                        |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Natalia Bidart):

 Replying to [comment:2 Matej Spiller Muys]:
 > The need for having db transactions as short as possible is quite
 general rule.

 I disagree with this. While I recognize that managing transaction
 thresholds and garbage collection may be critical for large-scale
 services, such as Instagram, I believe that the average Django project
 does not require such measures. Django has been around for nearly 21
 years, and this is the first time such a request has been reported in the
 issue tracking system. This suggests that the need for disabling GC to
 allow lowering the transaction max time is not a common concern among the
 broader Django users.

 > We are currently having our own atomic decorator that is disabling GC
 but I filled the issue because it seems like could be useful for wider
 audience. I will write to forum and see if there is more general need for
 high performance Django minding DB resources.

 Nice, do you have any benchmarks available, following Claude's ask? Please
 note that besides needing community consensus, we'd need a clear win on
 performance for a change like the one proposed. This is documented in
 https://docs.djangoproject.com/en/dev/internals/contributing/bugs-and-
 features/#requesting-performance-optimizations.

 > Example code that we use:
 > {{{
 > @contextlib.contextmanager
 > def disable_gc():
 >     _gc_was_enabled = gc.isenabled()
 >     if _gc_was_enabled:
 >         gc.disable()
 >     try:
 >         yield
 >     finally:
 >         if _gc_was_enabled:
 >             gc.enable()
 >
 > @contextlib.contextmanager
 > def atomic(using=None, savepoint=True, durable=False):
 >     with disable_gc(), transaction.atomic(using, savepoint, durable):
 >         yield
 > }}}

 I believe this code is not thread-safe nor reentrant-safe. For a proposal
 like this to be considered for inclusion in the core framework, we would
 need strong guarantees that it meets these criteria and that garbage
 collection is not inadvertently "disabled forever" due to unforeseen bugs.

 While the need for this functionality is valid and presents an interesting
 challenge, I reiterate that this is a niche use case, perhaps relevant to
 only 1% or even 0.5% of Django services deployed in the wild. As
 previously mentioned, Django aims to provide a robust, stable, and secure
 platform for common web service requirements, and this particular need
 feels outside the realm of what is considered "common."
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35853#comment:4>
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/01070192b4376579-d24777d2-bd58-40d7-ac14-fe6d8addf33e-000000%40eu-central-1.amazonses.com.

Reply via email to