You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mark Maunder <ma...@ziptree.com> on 2004/02/27 10:35:11 UTC

reloading modules in a handler with eval

Hi,

In a perl handler, I'm doing a stat on a module file, and if the file
has been modified, I'm reloading the module by slurping the file into a
scalar and eval'ing it. The module has a few subs and global vars that
have defaults set on initialization. I have about 20 modules I'm doing
this with (all subclasses of a parent generic module). I'm assuming the
subs will be overwritten in the module namespace, and global vars
re-initialized with their default values. 
All instances of objects created from these modules/classes are
destroyed at the end of each request, and this reload happens at the
beginning of a request before objects are instantiated. 

Anything wrong with doing this? It seems a little too easy! :)

Thanks,

Mark.


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by Mark Maunder <ma...@ziptree.com>.
Thanks for this Charles. I've never heard of vmstat, and after playing
with it for a few mins am amazed at my ignorance and its usefulness.

On Fri, 2004-02-27 at 21:07, Charles C. Fu wrote:
> In <10...@beast> on 27 Feb 2004,
>    Mark Maunder <ma...@ziptree.com> wrote:
> > Anyone know if the linux filesystem cache caches directory
> > information. I.e., does a stat by apache guarantee disk access?
> 
> This is almost certainly filesystem dependent; but for the usual
> filesystems (ext2, ext3, reiserfs, . . .) and options, yes, stat
> uses the cache.
> 
> This is easily verified by doing
> 
>   perl -e 'for (;;) { stat("filename"); };'
> 
> and using 'vmstat 1' or other tools to monitor the resultant disk
> activity.
> 
> -ccwf
> -- 
> Charles C. Fu
> Founder
> Web i18n, LLC
> www.web-i18n.net


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by "Charles C. Fu" <pe...@web-i18n.net>.
In <10...@beast> on 27 Feb 2004,
   Mark Maunder <ma...@ziptree.com> wrote:
> Anyone know if the linux filesystem cache caches directory
> information. I.e., does a stat by apache guarantee disk access?

This is almost certainly filesystem dependent; but for the usual
filesystems (ext2, ext3, reiserfs, . . .) and options, yes, stat
uses the cache.

This is easily verified by doing

  perl -e 'for (;;) { stat("filename"); };'

and using 'vmstat 1' or other tools to monitor the resultant disk
activity.

-ccwf
-- 
Charles C. Fu
Founder
Web i18n, LLC
www.web-i18n.net

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by Mark Maunder <ma...@ziptree.com>.
I forgot about that. I guess once all Apache kids exist, there's no way
to overwrite that module in shared memory without restarting Apache?
Silly question I guess. That's why they call it copy-on-write.

mark.

On Fri, 2004-02-27 at 13:15, Perrin Harkins wrote:
> Mark Maunder wrote:
> > For what I'm doing the only performance hit is the stat() on every
> > module
> 
> The other performance hit is that the memory used by these modules is no 
> longer shared by copy-on-write.
> 
> - Perrin
> 


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by Perrin Harkins <pe...@elem.com>.
Mark Maunder wrote:
> For what I'm doing the only performance hit is the stat() on every
> module

The other performance hit is that the memory used by these modules is no 
longer shared by copy-on-write.

- Perrin


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by Mark Maunder <ma...@ziptree.com>.
For what I'm doing the only performance hit is the stat() on every
module, which means disk access. That's 20 stats per request because
there are 20 modules. The 'touch' option  means only one stat instead of
20. Much better. 

Moving slightly OT. Anyone know if the linux filesystem cache caches
directory information. I.e., does a stat by apache guarantee disk
access? Or only if the file info isn't in the OS cache. I know mysql
relies heavily on the OS filesytem cache. Does Apache get any benefit
from it?


On Fri, 2004-02-27 at 11:09, David R. Baird wrote:
> On 27 Feb 2004 at 11:22, Tom Schindl wrote:
> 
> > I go with you in a dev environment still it decreases performance so
> > on a production server where modules should not change every minute I
> > never use it.
> 
> >From the Apache::Reload docs:
> 
> ----------
>     Special "Touch" File
> 
>     You can also set a file that you can touch() that causes the    
>     reloads to be performed. If you set this, and don't touch()
>     the file, the reloads don't happen. This can be a great boon
>     in a live environment:
> 
>     PerlSetVar ReloadTouchFile /tmp/reload_modules
> 
>     Now when you're happy with your changes, simply go to the
>     command line and type:
> 
>     touch /tmp/reload_modules
> 
>     And your modules will be magically reloaded on the next
>     request. 
> ----------
> 
> You can also explicitly register the modules you want to be 
> reloadable: 
> 
>     PerlInitHandler Apache::Reload
>     PerlSetVar ReloadAll Off
>     PerlSetVar ReloadModules "My::Foo My::Bar Foo::Bar::Test"
> 
> 
> HTH.
> 
> -- 
> Dr. David R. Baird
> ZeroFive Web Design
> dave@zerofive.co.uk
> http://www.zerofive.co.uk


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by "David R. Baird" <da...@zerofive.co.uk>.
On 27 Feb 2004 at 11:22, Tom Schindl wrote:

> I go with you in a dev environment still it decreases performance so
> on a production server where modules should not change every minute I
> never use it.

>From the Apache::Reload docs:

----------
    Special "Touch" File

    You can also set a file that you can touch() that causes the    
    reloads to be performed. If you set this, and don't touch()
    the file, the reloads don't happen. This can be a great boon
    in a live environment:

    PerlSetVar ReloadTouchFile /tmp/reload_modules

    Now when you're happy with your changes, simply go to the
    command line and type:

    touch /tmp/reload_modules

    And your modules will be magically reloaded on the next
    request. 
----------

You can also explicitly register the modules you want to be 
reloadable: 

    PerlInitHandler Apache::Reload
    PerlSetVar ReloadAll Off
    PerlSetVar ReloadModules "My::Foo My::Bar Foo::Bar::Test"


HTH.

-- 
Dr. David R. Baird
ZeroFive Web Design
dave@zerofive.co.uk
http://www.zerofive.co.uk

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by Tom Schindl <to...@gmx.at>.
I go with you in a dev environment still it decreases performance so on 
a production server where modules should not change every minute I never 
use it.

Nevertheless I don't know exactly how Apache::Reload is working but I 
suppose it deletes the module in %INC and reloads it using perls 
standard methods which is much wiser so one can import vars from the 
modules into its own namespace, syntax checking is done ...

Tom

Thomas Klausner wrote:
> Hi!
> 
> On Fri, Feb 27, 2004 at 09:35:11AM +0000, Mark Maunder wrote:
> 
> 
>>In a perl handler, I'm doing a stat on a module file, and if the file
>>has been modified, I'm reloading the module by slurping the file into a
>>scalar and eval'ing it. The module has a few subs and global vars that
>>have defaults set on initialization. I have about 20 modules I'm doing
>>this with (all subclasses of a parent generic module). I'm assuming the
>>subs will be overwritten in the module namespace, and global vars
>>re-initialized with their default values. 
>>All instances of objects created from these modules/classes are
>>destroyed at the end of each request, and this reload happens at the
>>beginning of a request before objects are instantiated. 
>>
>>Anything wrong with doing this? It seems a little too easy! :)
> 
> 
> It might even be easier:
> use Apache::Reload;
> 
> 


-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: reloading modules in a handler with eval

Posted by Thomas Klausner <do...@zsi.at>.
Hi!

On Fri, Feb 27, 2004 at 09:35:11AM +0000, Mark Maunder wrote:

> In a perl handler, I'm doing a stat on a module file, and if the file
> has been modified, I'm reloading the module by slurping the file into a
> scalar and eval'ing it. The module has a few subs and global vars that
> have defaults set on initialization. I have about 20 modules I'm doing
> this with (all subclasses of a parent generic module). I'm assuming the
> subs will be overwritten in the module namespace, and global vars
> re-initialized with their default values. 
> All instances of objects created from these modules/classes are
> destroyed at the end of each request, and this reload happens at the
> beginning of a request before objects are instantiated. 
> 
> Anything wrong with doing this? It seems a little too easy! :)

It might even be easier:
use Apache::Reload;


-- 
-> Austrian Perl Workshop - 20th-22nd May - http://vienna.pm.org/ <-

#!/usr/bin/perl                               http://domm.zsi.at
for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html