Discussion:
[htmltmpl] using cache
m***@comcast.net
2009-03-24 20:37:32 UTC
Permalink
as a new user to html::templates i've found it pretty easy to use but
quite slow. i've turned on cache'ing but there is still no
improvement and apache's log indicates that the files are being loaded
each time. so, what am i doing wrong? i've included the perl code i
use to create the template and the results shown in apache's log.
this shows, i believe, that each file is being loaded each time it's
referenced. it also shows another problem, that i encounter every so
often, that the file can't be found when, in fact, it's there. if i
simply reload the page the file is found the 2nd time. very confusing.

any help is greatly appreciated.

thanks,
tom

code snippet:
$tmpl = new HTML::Template(filename => "$page.html",
die_on_bad_params => 1, cache => 1, cache_debug => 1);

/var/log/apache2/error_log
[Tue Mar 24 14:06:11 2009] [notice] Apache/2.2.9 (Unix) PHP/5.2.6
mod_perl/2.0.2 Perl/v5.8.8 configured -- resuming normal operations
[Tue Mar 24 14:06:26 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : main.html =>
2f37e6f23ab3b64bc5f135082a0bdd86, referer: http://xwww.meds4vets.biz/index.pl
[Tue Mar 24 14:06:34 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : main.html =>
2f37e6f23ab3b64bc5f135082a0bdd86, referer: http://xwww.meds4vets.biz/index.pl?page=logout
[Tue Mar 24 14:06:45 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : aboutus.html =>
ffcd98c513174dbb29b79e75747db33f, referer: http://xwww.meds4vets.biz/index.pl?page=login
[Tue Mar 24 14:06:57 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : aboutus.html =>
ffcd98c513174dbb29b79e75747db33f, referer: http://xwww.meds4vets.biz/index.pl
[Tue Mar 24 14:07:05 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : products_01.html =>
e5f8705ae116b48a34bf98650f2f0d91, referer: http://xwww.meds4vets.biz/index.pl?page=aboutus
[Tue Mar 24 14:07:13 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : products_02.html =>
c4627d7e66e4f65f5a00bec98907dd5b, referer: http://xwww.meds4vets.biz/index.pl?page=products_01
[Tue Mar 24 14:07:22 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : products_03.html =>
d9c4c240921ca93f2e302fdf56e01904, referer: http://xwww.meds4vets.biz/index.pl?page=products_02&name_id=000001
[Tue Mar 24 14:07:33 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : products_02.html =>
c4627d7e66e4f65f5a00bec98907dd5b, referer: http://xwww.meds4vets.biz/index.pl?page=products_03
[Tue Mar 24 14:08:33 2009] [error] [client 127.0.0.1] HTML::Template-
new() : Cannot open included file products_01.html : file not found.
at /Library/Perl/5.8.8/HTML/Template.pm line 1658, referer: http://xwww.meds4vets.biz/index.pl
[Tue Mar 24 14:08:33 2009] [error] [client 127.0.0.1]
\tHTML::Template::_init_template('HTML::Template=HASH(0x8b60f0)')
called at /Library/Perl/5.8.8/HTML/Template.pm line 1238, referer: http://xwww.meds4vets.biz/index.pl
[Tue Mar 24 14:08:33 2009] [error] [client 127.0.0.1]
\tHTML::Template::_init('HTML::Template=HASH(0x8b60f0)') called at /
Library/Perl/5.8.8/HTML/Template.pm line 1124, referer: http://xwww.meds4vets.biz/index.pl
[Tue Mar 24 14:08:33 2009] [error] [client 127.0.0.1]
\tHTML::Template::new('HTML::Template', 'filename',
'products_01.html', 'die_on_bad_params', 0, 'cache', 1, 'cache_debug',
1, ...) called at /var/vhosts/meds4vets.biz/www/index.pl line 162,
referer: http://xwww.meds4vets.biz/index.pl
[Tue Mar 24 14:09:02 2009] [error] [client 127.0.0.1] ###
HTML::Template Cache Debug ### CACHE LOAD : products_01.html =>
e5f8705ae116b48a34bf98650f2f0d91

tourists don't know where they've been. travelers don't know where
they're going. -- paul theroux
Sam Tregar
2009-03-24 20:45:09 UTC
Permalink
Post by m***@comcast.net
as a new user to html::templates i've found it pretty easy to use but
quite slow. i've turned on cache'ing but there is still no
improvement and apache's log indicates that the files are being loaded
each time. so, what am i doing wrong? i've included the perl code i
use to create the template and the results shown in apache's log.
this shows, i believe, that each file is being loaded each time it's
referenced. it also shows another problem, that i encounter every so
often, that the file can't be found when, in fact, it's there. if i
simply reload the page the file is found the 2nd time. very confusing.
Are you running mod_perl? Are you pre-loading your cache during apache
startup as described in the docs? And finally, what makes you sure
HTML::Template is the source of your performance problem? It's actually
pretty rare in my experience.

-sam
Dawid Joubert
2009-03-24 21:39:53 UTC
Permalink
One problem you may find with the built-in caching is how it determines if a file has changed. It does this by getting the last modified time of the file and then comparing it to the cache version.

You should look into whether the modification time is cached.

I do not suggest you use the built-in cache as you should use one caching system for your entire setup. Memcached is the recommended one as once it runs out of memory it will discard the least accessed caches.

We wrote our own cache system with a preparser that used memcache. As we had over 10 webapps servers we only needed to store one copy of the template and that was on the memcached server.

Regards
Dawid Joubert
----- Original Message -----
From: Sam Tregar
To: ***@comcast.net
Cc: html-template-***@lists.sourceforge.net
Sent: Tuesday, March 24, 2009 8:45 PM
Subject: Re: [htmltmpl] using cache


2009/3/24 <***@comcast.net>

as a new user to html::templates i've found it pretty easy to use but
quite slow. i've turned on cache'ing but there is still no
improvement and apache's log indicates that the files are being loaded
each time. so, what am i doing wrong? i've included the perl code i
use to create the template and the results shown in apache's log.
this shows, i believe, that each file is being loaded each time it's
referenced. it also shows another problem, that i encounter every so
often, that the file can't be found when, in fact, it's there. if i
simply reload the page the file is found the 2nd time. very confusing.


Are you running mod_perl? Are you pre-loading your cache during apache startup as described in the docs? And finally, what makes you sure HTML::Template is the source of your performance problem? It's actually pretty rare in my experience.

-sam




------------------------------------------------------------------------------


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
Sam Tregar
2009-03-24 22:18:34 UTC
Permalink
Post by Dawid Joubert
One problem you may find with the built-in caching is how it determines
if a file has changed. It does this by getting the last modified time of the
file and then comparing it to the cache version.
You should look into whether the modification time is cached.
Good advice generally, but that doesn't appear to apply here. The log
messages show the files coming back with the same cache signature. I'm
guessing he's not running mod_perl which makes an in-memory cache pretty
useless, or he is and he's not pre-caching during startup.
Post by Dawid Joubert
We wrote our own cache system with a preparser that used memcache. As we
had over 10 webapps servers we only needed to store one copy of the template
and that was on the memcached server.
Memcached is a neat system.

-sam
m***@comcast.net
2009-03-25 00:44:40 UTC
Permalink
thanks for the fast response, guys. i really appreciate the help.
you're correct that i'm not running mod_perl. i thought simply
loading mod_perl was sufficient but obviously i was wrong, so i'm now
in the process of puzzling how to get this mod_perl thingy working. :)

cheers,
tom

tourists don't know where they've been. travelers don't know where
they're going. -- paul theroux
Sam Tregar
2009-03-25 01:33:09 UTC
Permalink
thanks for the fast response, guys. i really appreciate the help. you're
correct that i'm not running mod_perl. i thought simply loading mod_perl
was sufficient but obviously i was wrong, so i'm now in the process of
puzzling how to get this mod_perl thingy working. :)
Cool. The mod_perl mailing list is a good place for questions about that,
as is Perl Monks. I think you'll find the speedup from using mod_perl is
way more helpful than caching templates!

-sam
m***@comcast.net
2009-04-01 15:12:50 UTC
Permalink
just a follow-up to let you know that getting mod_perl working (i
didn't realize it was so involved) was the key to speeding things up.
you were absolutely correct that the speedup from mod_perl is way more
helpful than caching templates. thanks for the help and my apology
for accusing html::templates of being slow. :)

tom

tourists don't know where they've been. travelers don't know where
they're going. -- paul theroux

Loading...