So when are you releasing this cookbook ?  ;-)

Craig


On Wed, 14 Nov 2001, darren chamberlain wrote:

> dss <[EMAIL PROTECTED]> said something to this effect on 11/13/2001:
> > --- Chris Nandor <[EMAIL PROTECTED]> wrote:
> > > When I precompile all my templates, my CPU gets
> > > absolutely *pegged*
> > > sometimes, for a good 10 seconds or so.  If you have
> > > a bunch of httpds, and
> > > they are all compiling templates independently ...
> > > it can get nasty (yet
> > > another reason why I initially compile them in the
> > > root httpd and not in
> > > the children).
> > 
> > Interesting. Is this in the docs? I'm going to take a
> > look there next. If it's not, could you please explain
> > how to compile them in root httpd? (I think I remeber
> > this discussion on the list...I'll do a search there
> > as well).
> 
> I've been writing some documentation (which I've been calling
> Template::Cookbook) for internal use, and I have a piece
> concerning pre-compiling; here is the current version, which is
> more or less complete.  Hope this is useful for you.
> 
>   CACHING AND PERSISTANCE
>     A large part of the overhead associated with the Template Toolkit
>     is the compilation of the templates to native Perl. In order to
>     alleviate this somewhat, use the COMPILE_DIR and COMPILE_EXT
>     directives to have ensure that your templates get cached to disk
>     when they are compiled.
> 
>     Let's say you have the following code in your CGI script:
> 
>       my $t = Template->new(
>                 INCLUDE_PATH => "/web/templates",
>                 COMPILE_DIR => "/var/ttcache",
>               ) or die $Template::ERROR;
> 
>       $t->process("index.tmpl") or die $t->error;
> 
>     The first time this code is run, /web/templates/index.tmpl will
>     be compiled, and written to
>     /var/ttcache/web/templates/index.tmpl. For all subsequent calls
>     to process, the Template::Provider object will begin lookin in
>     /var/ttcache for the template; if it finds it, it compares the
>     timestamp to the template file in the real location, and
>     recompiles it only if the template is newer than the new version.
> 
>     For extremely long or complex templates, this can potentially be
>     a huge win; since templates compile to native Perl, which is
>     called in using require, Perl's native parsing does all the work.
>     Even for simple templates, this is a win, however, because the
>     Template::Parser object, which is large and complex, does not
>     need to be created for templates that are already compiled. This
>     is especially important for scripts that must run quickly and
>     often. Also see PRE-CACHING TEMPLATES, below.
> 
>   PRE-CACHING TEMPLATES
>     For busy sites, precompiling and pre-caching templates may
>     provide a significant performace gain. Pre-compilation can be
>     achieved very simply: we can use File::Find to walk our web root
>     (at /web/htdocs) and precompile each template. Note the OUTPUT =>
>     "/dev/null" line in the Template constructor; this ensures that
>     we don't get processed templates dumped to STDOUT (we probably
>     don't care about the output at this point).
> 
>       use Template;
>       use File::Find;
>       my $t = Template->new(
>                 INCLUDE_DIR => "/web/templates",
>                 COMPILE_DIR => "/var/ttcache",
>                 OUTPUT      => "/dev/null",
>               );
> 
>       sub process {
>         $t->process($_, { }) or warn $t->error;
>       }
> 
>       find(\&process, "/web/htdocs");
> 
>     These templates will now be precompiled in
>     /var/ttcache/web/templates, which is where the Template::Provider
>     objects will look for them at runtime.
> 
>     NB: Pre-compilation assumes that the COMPILE_DIR settings are
>     the same between calls to Template->new()!
> 
> (darren)
> 
> -- 
> Responsible behavior is the result of a socialization process.
> 
> _______________________________________________
> templates mailing list
> [EMAIL PROTECTED]
> http://www.template-toolkit.org/mailman/listinfo/templates
> 



Reply via email to