Mark Maunder wrote to Ryan Thompson:

> Ryan Thompson wrote:
>
> > There must be a faster way. I have thought about pre-compiling each
> > HTML file into a Perl module, but there would have to be an automated
> > (and secure) way to suck these in if the original file changes.
> >
> > Either that, or maybe someone has written a better parser. My code
> > looks something like this, to give you an idea of what I need:
>
> Sure there are tons of good template systems out there. I think
> someone made a comment about writing a template system being a
> right of passage as a perl developer. But it's also more fun to do
> it yourself.

:-)


> I guess you've tried compiling your regex with the o modifier?

Yep, problem is there are several of them. I've done some work
recently to simplify things, which might have a positive effect.


> Also, have you tried caching your HTML in global package variables
> instead of shared memory?  I think it may be a bit faster than
> shared memory segments like Apache::Cache uses. (The first request
> for each child will be slower, but after they've each served once,
> they'll all be fast). Does your engine stat (access) the html file
> on disk for each request? You mentioned you're caching, but
> perhaps you're checking for changes to the file. Try to stat as

My caching algorithm uses 2 levels:

When an HTML file is requested, the instance of my template class
checks in its memory cache. If it finds it there, great... everything
is done within that server process.

If it's not in the memory cache, it checks in a central MySQL cache
database on the local machine. These requests are on the order of a
few ms, thanks to an optimized query and Apache::DBI. NOT a big deal.

If it's not in either cache, it takes it's lumps and goes to disk.

In each cache, I use a TTL. (time() + $TTL), which is configurable,
and usually set to something like 5 minutes in production, or 60
seconds during development/bug fixes. (And, for this kind of data, 5
minutes is pretty granular, as templates don't change very often.. but
setting it any higher would, on average, have only a negligible
improvement in performance at the risk of annoying developers :-).

And, with debugging in my template module turned on, it has been
observed that cache misses are VERY infrequent (< 0.1% of all
requests).

In fact, if I use this cache system and disable all parsing (i.e.,
just use it to include straight HTML into mod_perl apps), I can serve
150-200 requests/second on the same system.

With my parsing regexps enabled, it drops to 50-60 requests/second.

So, to me, it is clear where performance needs to be improved. :-)

- Ryan

-- 
  Ryan Thompson <[EMAIL PROTECTED]>
  Network Administrator, Accounts

  SaskNow Technologies - http://www.sasknow.com
  #106-380 3120 8th St E - Saskatoon, SK - S7H 0W2

        Tel: 306-664-3600   Fax: 306-664-1161   Saskatoon
  Toll-Free: 877-727-5669     (877-SASKNOW)     North America

Reply via email to