Just to reiterate what for some of us is obvious and common knowledge:

If you are using a persistent environment like mod_perl, do *not*
recreate the top-level Template object on each hit.  Be sure you are
caching that between hits.  (If you have to change some parameters per
hit, there are options depending on the parameter.)

I have a client that had 38 boxes (each with 8 processors) running
Template Toolkit to generate web pages.  The boxes were typically
running with 50% CPU, and load average of 4 to 5. The top-level template
would typically pull in about 30 other templates per hit.  They asked me
to optimize that.

And then, jaw-droppingly, I discovered... they were effectively saying
Template->new on each hit.  This means that for every hit, all of those
30 templates would result in 60 stats (the template itself, and the perl
version) and then loading the Perl code for that template, firing up the
Perl compiler 30 times per hit.

With a one-line code change, I cached that.

When my change was pushed yesterday, those 38 boxes went to 20% CPU, and
a load average of 1.5 to 2.5.  Yes, about half.  Let me say that again.
*Half*.

(I've asked the client if I can take home the 17 boxes I'm now saving
them.  Apparently, "no". :)

So, learn from this.  Do *not* create the Template object on each hit!

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[email protected]> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to