On 18 maalis, 19:01, Aymeric Augustin
<aymeric.augus...@polytechnique.org> wrote:
> On 18 mars 2013, at 17:10, Shai Berger <s...@platonix.com> wrote:
>
> > If the persistent connections are thread-local, don't you want to close them
> > anyway when the thread exits?
>
> Yes, do you know how this could be achieved? I haven't found how to hook
> on thread termination.
>
> > ... but that fix will kill persistent connections under gunicorn.
>
> If you're talking of gunicorn + gevent, persistent connections simply cannot
> work, so this doesn't matter as long as Django doesn't use more database
> connections than "live" threads.
>
> > The solution that sounds "right" is to pool the persistent connections --
> > every thread that ends returns the connection to the pool.
>
> Yes, using an external pooler is the right solution in cases where persistent
> connections don't work.

It is possible to create a pool of connections to reuse inside Django.
Close releases back to pool, get_new_connection() fetches an unused
connection from the pool or creates a new connection if none
available.

The downside is that having a real connection pool is necessarily more
complex than the current setup. The problematic cases are how to deal
with `__del__` and plain concurrency can cause problems, too. However
a real pool would solve the above problems and thus it would be
possible to default persistent connections to on. The needed amount of
code is 100-200 LOC for the as-simple-as-possible pool.

For now I would just default the persistent connections feature to
off. I believe most Django projects fall into category where
connection creation performance doesn't matter. For those projects
where connection creation performance does matter turning persistent
connection on is easy enough. The default can be changed later on if
need be.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to