Jacob Kaplan-Moss wrote:
> 
> On Apr 5, 2006, at 2:09 PM, Ivan Sagalaev wrote:
>> How can this work? Django app connects to Postgres through psycopg,  
>> how
>> Apache can "hold" the connections that it doesn't know anything about?
>> Or does it?
> 
> It's not "holding" connections, per se... let me see if I can explain  
> it more clearly:
> 
> So the "problem" with Python (when it comes to web apps) is that  
> starting the interpreter is very expensive; on my main web server  
> ``time python -c 'import django.models'`` takes 1.5 seconds!  (This  
> is why anyone trying to do Django as a CGI is crazy).
> 
> To make this a non-issue, any sane environment shares one or more  
> Python interpreters across multiple requests (mod_python has one  
> interpreter per Apache child).  This means that any global variables  
> -- including the all-important ``sys.modules`` -- stay resident in  
> memory between requests.  Since Django's database connection is an  
> attribute in ``django.db``, it also sticks around between requests,  
> hence Postgres reporting idle connections.
> 
> Does that make sense?
> 
> I've consulted a database guru (Frank Wiles, http://revsys.com/)  
> about these "idle in transaction" connections a few times, and he  
> reassures me that they are less of a problem than recreating a  
> database connection upon each request.  His suggestion -- and mine --  
> is that if it's causing issues you should install a connection pool  
> (pg_pool is the best one) between Django and your database.
> 
> Again, I really want to back this change out.  My off-the-cuff  
> measurements (not very good, probably) show about a 5% performance  
> hit when closing the connection each time, and although that's not  
> much, that's 5% less hardware I have to buy.
> 
> I'm sorry I didn't speak up *before* this change got checked in; I  
> missed the thread until I saw the changeset.  Are there any serious  
> objections to backing this out?


hi Jacob, many thanks for the explanation.

(and sorry to jump into the discussion)..

the original poster (luke plant) said that:

"
It appears
that connections are not being closed at all.  With every hit I'm
getting another entry in the process table
"

so if he's only hit by the reuse-open-connection effect, it should be 
pretty easy to reproduce:

setup apache with maxclients = 3, and do more than 3 requests.

if the number of open psql connections stays 3, everything is ok.
if it increases, there's a problem.

perhaps this would help to clarify the situation.


gabor

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers
-~----------~----~----~----~------~----~------~--~---

Reply via email to