FAQ
Hey all,

I have this CMS which generates static content into a Catalyst
application. Because there is dynamic stuff like "Most recent stories"
on almost every page, I'm rendering TT code into the content generated
by the CMS and the final page is then eval'd by the main Catalyst TT
view. (It's similar to having the CMS generate PHP code which is then
eval'd by the PHP interpreter. I know that this somewhat violates the
separation of concerns rule but it makes life a _lot_ easier).

The TT code mainly consists of some DBIC model calls. Unfortunately,
even with caching (via DBIx::Class::Cursor::Cached and
Cache::Memcached), this slows down the average page rendering time
quite considerably. Without the dynamic parts the development server
is able to do about 15 reqs/sec. With only 3-4 (cached) DBIC calls in
between this goes down to 7 reqs/sec. Now I'm wondering if:

a) this is really something to worry about?
b) there is something like page fragment caching which allows me to
not cache DBIC objects but generated HTML in an elegant way (without
having to wrap each TT code snippet with cache get/set calls)?
Catalyst::Plugin::PageCache only allows the caching of whole pages
which currently is not an option because there is more dynamic stuff
(like logged-in user) added to the final page. AFAIK, page fragment
caching is quite common in other frameworks (RoR comes to mind ...).
c) somebody smarter than me has a better idea how to solve this problem? :)

Thanks a lot for your advice!

--Tobias

Search Discussions

  • Mike Whitaker at Jan 20, 2010 at 9:40 am

    b) there is something like page fragment caching which allows me to
    not cache DBIC objects but generated HTML in an elegant way (without
    having to wrap each TT code snippet with cache get/set calls)?
    Catalyst::Plugin::PageCache only allows the caching of whole pages
    which currently is not an option because there is more dynamic stuff
    (like logged-in user) added to the final page. AFAIK, page fragment
    caching is quite common in other frameworks (RoR comes to mind ...).
    One way to acheive this is to front-end your site with the varnish proxy and use ESI.
  • Carl Johnstone at Jan 20, 2010 at 9:43 am

    Tobias Kremer wrote:
    c) somebody smarter than me has a better idea how to solve this
    problem? :)
    Use Varnish as a caching-proxy in front-of your app. Use ESI to include the
    fragments and set appropiate cache-control headers in those reponses so
    Varnish can cache appropiately.

    Carl
  • Tobias Kremer at Jan 20, 2010 at 9:51 am

    On Wed, Jan 20, 2010 at 10:43 AM, Carl Johnstone wrote:
    Use Varnish as a caching-proxy in front-of your app. Use ESI to include the
    fragments and set appropiate cache-control headers in those reponses so
    Varnish can cache appropiately.
    Thanks! Unfortunately I don't see changing our current delivery
    infrastructure to include Varnish anytime soon so I'm stuck with
    solving this problem at application level ... :(

    Any other ideas?

    --Tobias
  • Peter Karman at Jan 20, 2010 at 2:31 pm

    Tobias Kremer wrote on 01/20/2010 03:51 AM:
    Any other ideas?
    Template::Plugin::Cache ?

    --
    Peter Karman . http://peknet.com/ . peter@peknet.com
  • Tomas Doran at Jan 20, 2010 at 8:00 pm

    On 20 Jan 2010, at 09:37, Tobias Kremer wrote:
    b) there is something like page fragment caching which allows me to
    not cache DBIC objects but generated HTML in an elegant way (without
    having to wrap each TT code snippet with cache get/set calls)?
    As noted by already, serving ESI is a good way to do this. I'd
    recommend Catalyst::View::Component::SubInclude for this.

    It would be perfectly possible (and in fact quite easy) to write a
    backend for that which cached the fragment for you...

    So you can get the best of all worlds - use SubRequest in development,
    cache the fragments now for production, and when you come to scale a
    lot - you can use varnish/ESI straight away, just by changing config -
    rather than needing to rework parts of your app. :)

    Cheers
    t0m
  • Tobias Kremer at Jan 21, 2010 at 9:08 am

    On Wed, Jan 20, 2010 at 9:02 PM, Tomas Doran wrote:
    As noted by already, serving ESI is a good way to do this. I'd recommend
    Catalyst::View::Component::SubInclude for this.
    It would be perfectly possible (and in fact quite easy) to write a backend
    for that which cached the fragment for you...
    So you can get the best of all worlds - use SubRequest in development, cache
    the fragments now for production, and when you come to scale a lot - you can
    use varnish/ESI straight away, just by changing config - rather than needing
    to rework parts of your app. :)
    Okay, this really makes Varnish/ESI an attractive route and we'll
    definitely aim at taking it in the not so distant future :)

    Meanwhile, I played with Template::Plugin::Cache which unfortunately
    has problems with UTF-8 content and Memcached because the UTF-8 flag
    is not properly restored on get(). Should be easy to fix with
    something like: Encode::_utf8_on( $result );

    It would be awesome if TT allowed something like this:

    [% CACHE key => 'latest-stories' ttl => '3600' %]
    ... Expensive stuff ...
    [% END %]

    Or something similar to Mason's cache_self() method.

    But these are different discussions for different mailing lists :)

    Thanks for your advice!

    --Tobias
  • Octavian Rasnita at Jan 21, 2010 at 9:53 am
    From: "Tobias Kremer" <tobias.kremer@gmail.com>
    Meanwhile, I played with Template::Plugin::Cache which unfortunately
    has problems with UTF-8 content and Memcached because the UTF-8 flag
    is not properly restored on get(). Should be easy to fix with
    something like: Encode::_utf8_on( $result );
    The author of T::P::Cache said that this bug is solved if instead of Cache
    is used a CHI object.

    Octavian
  • Kmx at Jan 29, 2010 at 11:29 am
    Hi,
    Ok, so I may be getting somewhere with this, but I can't tell.

    I installed the .dll found here: http://www.fastcgi.com/dist/ and now my
    config looks like the following:

    ...

    Any ideas on what I might try next?
    Have you tried the mod_fastcgi binaries and config example described on
    catalyst wiki?

    http://dev.catalystframework.org/wiki/deployment/apache_fastcgi_win32

    --
    kmx

    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100129/bea50902/attachment.htm

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJan 20, '10 at 9:37a
activeJan 29, '10 at 11:29a
posts9
users7
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2021 Grokbase