[mod_python] mod_python slowness

Alex Turner aturner at neteconomist.com
Fri May 16 12:27:38 EST 2003


DOH!

I found the problem.  And can easily explain the discrepancy between
running the script stand alone vs in apache.  There is one major
difference between apache, and standalone: Cookies.  My Container object
that is passed to each tag function was fetching the cookies from the
request object for each execution! I moved the code into the right place,
i.e. where the request object initialy get's dealt with, and that has
of course cured the problem!

Many thanks to all who have replied.

And as a random editorial, I have to say that I enjoy working with 
mod_python/python as a web platform far more than any other I've used 
previously including php, perl, java and coldfusion.  It has both the 
flexibility and the power to make web development fast and easy (thank 
goodness for proper stack traces and a consistance language API!)

Alex Turner
NetEconomist

On Fri, 16 May 2003, Gregory (Grisha) Trubetskoy wrote:

> 
> The times listed below, are these averages of multiple iterations (e.g.
> 10000) or just a one time try?
> 
> Anyway - it doesn't look like this is where the bottleneck is - you
> mentioned before that a page that took 2.2 seconds to load takes 23
> seconds - that's almost 21 seconds of difference whereas below you have a
> slowdown of 0.8 secs.
> 
> Grisha
> 
> 
> On Fri, 16 May 2003, Alex Turner wrote:
> 
> >
> > 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
> > executes
> > 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):
> >  start=time.time()
> >  self.query=query
> >  self.counter=0;
> >  self.lresults_l=self.query.getresult()
> >  self.dresults_l=self.query.dictresult()
> >  self.fresults_l=[]
> >
> >  # Copy the indexed/dict values into fresults
> >  for a in range(len(self.lresults_l)):
> >    x=0
> >    self.fresults_l.append({})
> >    for b in self.lresults_l[a]:
> >       self.fresults_l[a][x]=b
> >       x=x+1
> >
> >    for b in self.dresults_l[a].keys():
> >       self.fresults_l[a][b]=self.dresults_l[a][b]
> >
> >  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
> > NetEconomist
> >
> > 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
> > >
> >
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
> >
> 



More information about the Mod_python mailing list