Re: Importing Cheetah.Template.Template unusually slow?

Matthew Beauregard <[email protected]> Thu, 28 Jan 2010 08:19:03 +1100
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
On 28/01/2010, at 5:02 AM, R. Tyler Ballance wrote:

> 
> On Wed, 27 Jan 2010, Matthew Beauregard wrote:
> 
>> Hi,
>> 
>> I was trying to speed up my CGI, and I worked out that the lion's share of execution time was taken up by the Cheetah import.  Is 0.7s unusually slow?  Where should I start in trying to speed it up?
> 
> What version are Cheetah are you running? I'm also curious if your machine
> isn't generating a Template.pyc for Template.py, causing the interpreter to
> generate new byte-code for every request.

Hi Tyler,

It's version 2.4.1, and the installer generated the pyc:

-rwxr-xr-x  1 root  admin  84747 27 Jan 21:37 /Library/Python/2.6/site-packages/Cheetah-2.4.1-py2.6-macosx-10.6-universal.egg/Cheetah/Template.py
-rw-r--r--  1 root  admin  71104 27 Jan 21:37 /Library/Python/2.6/site-packages/Cheetah-2.4.1-py2.6-macosx-10.6-universal.egg/Cheetah/Template.pyc


I did some other comparisons, all for Cheetah 2.4.1:
OSX 10.6, system python 2.6.1:  0.7s
OSX 10.5, system python 2.5.1:  0.7s
OSX 10.6, macports python 2.6.4:  0.1s
Ubuntu Hardy, python 2.5:  0.1s

So I guess I'd have to blame some interaction between Cheetah and Apple's framework python.  I'm not sure what to do next.


> It's also worth mentioning that in a CGI environment you are going to have some
> bit of slow-down with imports to begin with, you can mitigate this by making
> sure that a new instance of the interpreter isn't started for each requests,
> allowing a single instance service thousands of requests (mod_python has some
> options for this IIRC)

That'd be a massive job at this point, I think the project is welded to CGI.  But that 0.7s import accounts for something like 80% of the average execution time, solving it would be a big win.

thanks,
Matthew


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com