#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 Matej Spiller Muys):

 The need for having db transactions as short as possible is quite general
 rule.

 In other languages, GC is not blocking the main thread. In Python that is
 unfortunately not the case.
 Basically if you can get eliminate GC you can scale better. And also DBA
 will be much happier because it won't hog the database.
 We are monitoring the database performance and are trying to have
 transactions duration at max 0.5 seconds.
 If you have shorted transactions you also need less concurrent connections
 as well.

 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.

 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
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35853#comment:2>
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/01070192b30767d2-09412766-49a0-4514-99cf-fd2063cbb598-000000%40eu-central-1.amazonses.com.

Reply via email to