On Wed, 9 May 2001, Morbus Iff wrote:

> Date: Wed, 09 May 2001 17:14:10 -0400
> From: Morbus Iff <[EMAIL PROTECTED]>
> To: G.W. Haywood <[EMAIL PROTECTED]>
> Cc: [EMAIL PROTECTED]
> Subject: Re: mod_perl and 700k files...
>
>  >> Ahhh. Ok. What's this $SIG{'USR2'} thingy. What's that do?
>  >
>  >http://perl.apache.org/guide
>
> Well, that's all fine and dandy, and I've gone through there before, but
> the only thing the search engine brings up concerning USR2 is:
>
>    >The above code asigns a signal handler for the USR2 signal.
>    >This signal has been chosen because it's least likely to be
>    >used by the other parts of the server.
>
> That, unfortunately doesn't tell me what causes a USR2 signal to be sent to
> Apache. Or when it's caused. I only want to reload the file when said file
> has changed. Am I supposed to do some checking against the file -M time
> myself, and then send a USR2 signal myself?
>
>
> Morbus Iff
> .sig on other machine.
> http://www.disobey.com/
> http://www.gamegrene.com/
>

Well, here's an idea that I've used before, though this will only
cache the data in each child and not when the parent starts up.
Still...  Here's pseudo-code version of my idea:

package Foo;

use strict;

use vars qw[ %CACHE ];
%CACHE = ();

use constant EXPIRES  => 60*5; # five minutes

sub handler {
    my $r = shift;

    my $expires = $CACHE{'expires'} || 0;

    if ( $expires < time ) {
        #
        # stat the file, figure out when it was changed
        #
        my $mtime = ...

        if ( $mtime > $CACHE{'mtime'} ) {
            #
            # get your new data here
            #
            $CACHE{'data'}  = ...
            $CACHE{'mtime'} = $mtime;
        }

        #
        # reset CACHE's expire time
        #
        $CACHE{'expires'} = time + EXPIRES;
    }

    $r->print( $CACHE{'data'} );

    return OK;
}

You see that my idea is to eliminate stat'ing the file on every
request by caching data for at least 'x' amount of time.  Then when
the data expires, stat the file and reload only if it has changed.
Again, this means each child maintains its own cache, but it might not
be that bad (?).

ky

Reply via email to