Using _default_manager in a model causes many idle MySQL connections. (Django 1.0)

20 views
Skip to first unread message

MikeL

unread,
Mar 19, 2009, 5:06:31 PM3/19/09
to Django users
I'm using the code from:

http://www.eflorenzano.com/blog/post/easy-multi-database-support-django/

After repeated use, there can be over a hundred idling connection to
MySQL for both production and development builds. Removing the
Multiple DB in the model causes the symptoms to stop.

I've been trying to track down where the circular reference (if it's
that) is causing the connections to not be closed/deleted without much
luck. Is this use of _default_manager just plain flawed? If not, does
anyone know if there is a working fix?

TIA,

Michael LaRue

Alex Gaynor

unread,
Mar 19, 2009, 5:10:04 PM3/19/09
to django...@googlegroups.com
It's not a default manager issue, the issue is by default django closes the connection at the end of the request, but it only tracks the default connection, so your cusotm multidb support isn't tracked.

Alex

--
"I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire
"The people's good is the highest law."--Cicero

MikeL

unread,
Mar 19, 2009, 7:52:08 PM3/19/09
to Django users
I wasn't sure where this stuff was being tracked, but I did find a
circular reference in the database wrapper. The DatabaseCreation and
DatabaseIntrospection objects being created in the MySQL wrapper where
passing references of itself, but there wasn't a per-defined method
for removing those references.

Should BaseDatabaseIntrospection and BaseDatabaseCreation be holding a
weakref of the database wrapper instead?
Or is there some connection pooling system that needs to be aware of
the Mulit-db stuff?
Does any of this seem sane?

My _hack_ (temp and not perfect I know) involved a class wrapping
around QuerySet and monitoring the clone counts (split per wrapper
instance) so when the final QuerySet was deleted it would clear the
two references allowing the database wrapper to be garbage collected.

TIA,

Michael LaRue

On Mar 19, 2:10 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:

J

unread,
Mar 31, 2009, 5:26:01 AM3/31/09
to Django users
Hello Michael,

Would you share your temp patch here?

TIA,

J

Guillaume Carbonneau

unread,
Apr 1, 2009, 2:45:38 PM4/1/09
to Django users
I too am interested in seeing this patch. I'm getting lots of idle
connections in postgres
Reply all
Reply to author
Forward
0 new messages