----- Original Message -----
From: "Randal L. Schwartz" <[EMAIL PROTECTED]>
To: "Peter Bi" <[EMAIL PROTECTED]>
Cc: "Perrin Harkins" <[EMAIL PROTECTED]>; "md" <[EMAIL PROTECTED]>;
"Stas Bekman" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, June 25, 2002 10:18 AM
Subject: Re: when to mod_perl?


> >>>>> "Peter" == Peter Bi <[EMAIL PROTECTED]> writes:
>
> Peter> I have a question regarding to the cached files. Although the
> Peter> maximal period is set to be 24 hours in httpd.conf's proxy
> Peter> settings, many of the files, which were cached from the backend
> Peter> mod_perl dynamical program, are strangely modified every a few
> Peter> minutes. For all the files I checked so far, they do look to be
> Peter> modified because the hex strings on top of the files (such as
> Peter> 000000003D189FC2) are different after each modifications.
>
> If you're talking about www.stonehenge.com, I don't provide
> last-modified for any of the HTML pages: they're all dynamic.  If the
> proxy server is caching them, it's going to still punch through to the
> back for each hit.

That is one of our sites.

>
> Similarly, if you are talking about your own site, and you *do*
> provide a mostly useless "last modified" time, then the front end is
> still going to go to the back end and say "I've got a version from
> time $x, is that current?" and if you're not handling
> "if-modified-since", then every hit will be cached, uselessly.
>

I used:
$r->update_mtime($id); # id is less than the current time and does not
change for a specific page
$r->set_last_modified;
if ($r->protocol =~ /(\d\.\d)/ && $1 >= 1.1){
      $r->header_out('Cache-Control' => "max-age=" . 100*24*3600);
} else {
      $r->header_out('Expires' => HTTP::Date::time2str($id + 100*24*3600));
}

It would not be surprising if none of the dynamic pages created was cached,
which then meant I had improper headers in mod_perl. In fact, they do serve
a number of views (maybe several tens) before modifying in the proxy
directory again. For example, I checked a file status:
$last access time: Tue Jun 25 11:44:12 2002
$last modify time: Tue Jun 25 11:40:52 2002
and for the same file later:
$last access time: Tue Jun 25 11:51:14 2002
$last modify time: Tue Jun 25 11:44:54 2002
so they were modified but not for every hits.

> I avoid that on stonehenge by not providing last-modified for any of
> my HTML pages.  mod_proxy thus has no idea about caching, so it's all
> dynamic.  My images automatically have last-modified, and thus the
> cache can check for updates with if-modified-since, using the cache
> when needed.  If I was really smart, I'd use mod_expires to say "this
> image is good for $N hours", and then the front end wouldn't even
> touch the back end at all.
>

But if one makes a proper header, the proxy would not distinquish whether it
is static or dynamic. It should deliver or cache all the backend pages the
same way, providing the headers are right.

Here is another strange clue for me. The cached files have three extra
request headers "X-Forwarded-For:", "X-Host: ",  "X-Server-Hostname: " (from
mod_proxy_forward). While the files are modified continuously, the
"X-Forwarded-For" header, which record a browser's IP,  does NOT change
although the later hits come from completely different IPs.


> As I said, as long as my loadav is low enough for my current hits, I've
> got better things to work on. :)
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
> <[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
> See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
training!
>


Peter Bi

Reply via email to