How to reload PERL module in all Apache children
Hello, I was wondering if there is a possibility to reload PERL module compiled into Apache with Apache::Registry (and I want to reload this module in all Apache children processes) by running reload-program once. For example Apache::Reload must be set as PerlInitHandler, so it's handler method is run every time request comes to Apache. What I'd like to do is to reload specified (or all) module by running the program ONCE. I tried using something like perl-status: Location /mod-perl-reload SetHandler perl-script PerlHandler Apache::MyReloadModule /Location where MyReloadModule's handler was deleting specified module from %INC and reloading it by require, but it didn't satisfy me becouse changes weren't seen in apache children processess (at least I think so), so I wrote something like this in MyReloadModule: sub handler { my $r = shift; Apache-request($r); . .sending HTML . foreach my $k (keys %INC) { $r-print($kBR); } $r-print(PID $$); $r-print(/BODY/HTML); } and I realised that changes I have made to %INC in one child process aren't seen in another one. So my problem can be set in another way: Do apache children communicate between themselves? Is it possible to write such a reloader script as I wanted to write? Maybe somebody already done this? Thanks in advance, Tomek Paterek
Re: How to reload PERL module in all Apache children
Waldek Grudzien wrote: Hello, I was wondering if there is a possibility to reload PERL module compiled into Apache with Apache::Registry (and I want to reload this module in all Apache children processes) by running reload-program once. For example Apache::Reload must be set as PerlInitHandler, so it's handler method is run every time request comes to Apache. What I'd like to do is to reload specified (or all) module by running the program ONCE. I tried using something like perl-status: Location /mod-perl-reload SetHandler perl-script PerlHandler Apache::MyReloadModule /Location where MyReloadModule's handler was deleting specified module from %INC and reloading it by require, but it didn't satisfy me becouse changes weren't seen in apache children processess (at least I think so), so I wrote something like this in MyReloadModule: sub handler { my $r = shift; Apache-request($r); . .sending HTML . foreach my $k (keys %INC) { $r-print($kBR); } $r-print(PID $$); $r-print(/BODY/HTML); } and I realised that changes I have made to %INC in one child process aren't seen in another one. So my problem can be set in another way: Do apache children communicate between themselves? no Is it possible to write such a reloader script as I wanted to write? no Maybe somebody already done this? see above The processes are forked and don't share the perl iterpreter, that's why it's impossible to do what you are trying to do. If you try to reload data it's doable by many ways (IPC, dbm, etc), not the code. Currently Apache::Reload or its equivalent your only solution. With mod_perl 2.0 it'll be doable, if you run a single threaded server. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: How to reload PERL module in all Apache children
Hi Stas, I was wondering if there is a possibility to reload PERL module compiled into Apache with Apache::Registry (and I want to reload this module in all Apache children processes) by running reload-program once. Currently Apache::Reload or its equivalent your only solution. With mod_perl 2.0 it'll be doable, if you run a single threaded server. So you mean any modules changed can be reloaded to all children, without actually terminating and starting the server ? (or does single threaded means there are no children ?) Sreeji __ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com
Re: How to reload PERL module in all Apache children
Sreeji K Das wrote: Hi Stas, I was wondering if there is a possibility to reload PERL module compiled into Apache with Apache::Registry (and I want to reload this module in all Apache children processes) by running reload-program once. Currently Apache::Reload or its equivalent your only solution. With mod_perl 2.0 it'll be doable, if you run a single threaded server. So you mean any modules changed can be reloaded to all children, without actually terminating and starting the server ? (or does single threaded means there are no children ?) Sorry, I should have said within a single process with multiple threads. I just said it'll be doable because of threads, (which all share the same process memory). I'm not sure if this already works this way. Give it a try, Apache::Reload is a now in the 2.0 core. __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [Fwd: Re: How to reload PERL module in all Apache children]
if you use Apache::Reload with a threaded MPM and multiple interpreters, the modules will be reloaded by each interpreter as they are used, not every interpreter all at once. similar to 1.x where each child has its own interpreter, the modules are reloaded as each kid is hit with a request. note that if a module is loaded at startup, the syntax tree of each subroutine is shared between interpreters (big win), but each subroutine has its own padlist (where lexical my variables are stored). once Apache::Reload reloads a module, this sharing goes away and each interpreter will have its own copy of the syntax tree for the given subroutines.
Re: [Fwd: Re: How to reload PERL module in all Apache children]
[EMAIL PROTECTED] wrote: if you use Apache::Reload with a threaded MPM and multiple interpreters, the modules will be reloaded by each interpreter as they are used, not every interpreter all at once. similar to 1.x where each child has its own interpreter, the modules are reloaded as each kid is hit with a request. thanks for correcting me. It's all about interpreters and not threads, so it's the same for the code with forked and threaded httpds. But if talk about futuristic Solar variables (perl globals shared between threads). what if a solar variable is a reference to CODE? Can this be shared? If so, will reloading this variable in one interpreter affect others? Also if we put the sharing aside for a moment and assuming that we have a pool of interpreters with idle interpreters in it, there can be a thread that monitors changed modules and update the idle interpreters by making them reload the code and put them in the head of the list. This should save the overhead of reloading during a request. Does this make sense? __ Stas BekmanJAm_pH -- Just Another mod_perl Hacker http://stason.org/ mod_perl Guide --- http://perl.apache.org mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com http://modperlbook.org http://apache.org http://ticketmaster.com
Re: [Fwd: Re: How to reload PERL module in all Apache children]
On Fri, 12 Apr 2002, Stas Bekman wrote: But if talk about futuristic Solar variables (perl globals shared between threads). what if a solar variable is a reference to CODE? Can this be shared? If so, will reloading this variable in one interpreter affect others? even if that would work, it would kill performance due to required mutex locking. and that locking would need to happen in the perl core, unlike simple scalars, arrays and hashes. Also if we put the sharing aside for a moment and assuming that we have a pool of interpreters with idle interpreters in it, there can be a thread that monitors changed modules and update the idle interpreters by making them reload the code and put them in the head of the list. This should save the overhead of reloading during a request. Does this make sense? there already is a plan to have a low-priority thread that monitors idle interpreters. this would be a pluggable interface, so you can do whatever you want with the interpreter via callback hooks. but that'll all wait until well after everything else is solid with ithreads, including and most important: perl 5.8.x
Re: [Fwd: Re: How to reload PERL module in all Apache children]
[EMAIL PROTECTED] wrote: On Fri, 12 Apr 2002, Stas Bekman wrote: But if talk about futuristic Solar variables (perl globals shared between threads). what if a solar variable is a reference to CODE? Can this be shared? If so, will reloading this variable in one interpreter affect others? even if that would work, it would kill performance due to required mutex locking. and that locking would need to happen in the perl core, unlike simple scalars, arrays and hashes. Does it look you'll be able to get the solar variables idea to work for those data types? - Perrin
Re: [Fwd: Re: How to reload PERL module in all Apache children]
On Thu, 11 Apr 2002, Perrin Harkins wrote: Does it look you'll be able to get the solar variables idea to work for those data types? i had a simple prototype way back that sorta worked for simple scalars, probably won't take it any further now that there is threads::shared in 5.7.x. haven't tried it but i believe the concept is the same.