[mod_python] How to call a webpage on the same server?

berry groenendijk berry.groenendijk at gmail.com
Tue May 31 17:29:10 EDT 2005


Hi Nicolas,

I have been doing some experimenting. Like you said I just called 
urllib2.urlopen. Still this is way too slow. To get the response it takes 
about 40 milliseconds.

I then ran a little Python script that calls the same page, using the 
method. I started this script on the command line. When I call that page it 
takes about 21 milliseconds. About twice as fast.

When I run Siege against page A it reaches about 42 transactions/sec, so 
about 20 milliseconds per request.

Then I build a page that uses Sarissa and and the httprequest object. So, 
first the HTML page gets loaded. On that page is a button which fires a 
javascript. That script loads the same page A. It then loads an xslt file 
and then does a conversion. Despite the conversion this takes less than 4(!) 
milliseconds.

Conclusion: hmmm, difficult. Seems that urllib2.urlopen isn't that slow 
after all. Still it looks like it is twice as slow called from within 
mod_python compared to when you fetch that same page via Python in a 
terminal window. What does surprise me is how quick the client side 
javascript code is. It could be that my time measurement there isn't that 
accurate. But, it also "feels" very quick. Perhaps this has something to do 
with the browser (Firefox) keeping connections open to the webserver.

Hmmm, I have to rethink what I am trying to accomplish here... I will have 
to do some more experimenting.

Thanks very much for your help!

Berry.

On 5/31/05, Nicolas Lehuen <nicolas.lehuen at gmail.com> wrote:
> 
> Hi Berry,
> 
> First check whether this is really due to the way you call your page.
> Don't parse the page, just call urllib2.urlopen and see what happens.
> 
> Regards,
> Nicolas
> 
> 2005/5/30, berry groenendijk <berry.groenendijk at gmail.com>:
> > Hi!
> >
> > Strictly speaking this is not a mod_python question. Please accept my
> > apologies. Still I hope somebody can give me some hints.
> >
> > I am using mod_python 3.1.3 with mod_python servlets. I am experimenting
> > with a REST-style interface to my website.
> >
> > This is the situation. Page A in my website returns a RSS XML file. I 
> want
> > to use this output on page B in the same website. To present page B to 
> the
> > user I do a little server side conversion to HTML. The problem is: this 
> is
> > very slow! My guess is that it has to do with the way I call page A.
> >
> > Here is part of the code of page B:
> >
> >
> > import os
> > import urllib
> > from cElementTree import iterparse
> >
> > import _SitePage as sitepage
> > import _Config as config
> >
> > class keywordshtml2(sitepage.SitePage):
> >
> > def write_content(self):
> >
> > url_keywords = "http://%s/keywords" % self.req.hostname
> >
> > self.writeln('<h1>List of articles by keyword</h1>')
> > self.writeln("<p>Available keywords:")
> > for event, elem in iterparse(urllib.urlopen(url_keywords)):
> > if elem.tag == "item":
> > self.writeln("<a href='#%(x)s'>%(x)s</a>, " % ({'x':
> > elem.findtext("title")}))
> > elem.clear()
> > self.writeln("</p>")
> >
> > Is there a better way to call page A from within page B?
> >
> > --
> > Berry Groenendijk
> > http://www.bersie.de
> >
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
> >
> >
> >
> 



-- 
Berry Groenendijk
http://www.bersie.de
Skype: berryg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050531/54664ebd/attachment.html


More information about the Mod_python mailing list