[mod_python] mod_python slowness

Alex Turner aturner at neteconomist.com
Fri May 16 10:34:39 EST 2003

It's very unlikely to be a network problem because both the database and 
the web server are running on the same host.  The timings that I took were 
done by placing a start=time.time() at the top of the code section that 
the file, and a print time.time()-start at the end, so I'm fairly 
convinced that these are accurate.  I then placed more time tests around 
other parts of the mechanism which allowed me to gauge how long each 
segment of the run takes.  I have found a serious flaw in my database 
class, having corrected that though, I found something interesting:

This is my init routine for by DBResult class:

def __init__(self,query):

 # Copy the indexed/dict values into fresults
 for a in range(len(self.lresults_l)):
   for b in self.lresults_l[a]:

   for b in self.dresults_l[a].keys():

 print "Init time %f<br>\n" % (time.time()-start)

It's not pretty, but it does show something wierd:

inside apache this gives a time of: 0.178554 secs
outside apache this gives a time of: 0.093750 secs

almost twice as fast.

Maybe this is a pg module problem, I don't know, but it's certainly wierd!

Alex Turner

On Tue, 13 May 2003, Jack Diederich wrote:

> > 
> > I'm pretty sure this is not a DNS problem.  I can break down each loop
> > that calls the database, and it shows 0.7 seconds per row returning
> > instead of like 0.03 seconds.  The dns servers are all configured
> > correctly for both forward and reverse lookups, and I do not have the same
> > problems in PHP (other the fact that PHP is crap compared to python - but
> > it's not this slow).
> Are you doing anything wierd like running apache or progres
> through inetd (so it has to start a new process for every
> request)?  Or are you doing a new database connection for
> each row?
> If the identical python program takes 1/10th the time running
> stand-alone I think the DNS was one the right track - it must
> be a network related problem.
> You might also want to print to the resulting page the time
> the process took from start to finish.  If the page is very
> complicated it might look slower even if it isn't.
> You can also try commenting out all the database calls and
> timing the stand alone and mod_python versions.  That will
> at least allow you to narrow down the problem.  Also consider
> using 'strace' on the stand alone and the apache version.
> Compare the system calls between the two to see if something
> pathological is happening in the mod_python case.
> -jack

More information about the Mod_python mailing list