Mailing List Archive

Question re preloading embperl and apache shutdown
I am now using Apache2.2, mod_perl 2 and Embperl 2.3. I am also
preloading my Embperl code via startup.pl, and finding that "apachectl
stop" seems to call my preload routine even when shutting down apache,
which makes it take an absurdly long time to cycle the server when I
change code. This didn't use to happen with apache1.3. Is anyone aware
of a way to detect from within startup.pl whether we are starting up or
shutting down? Then I guess I could skip the preload myself if we're
stopping... any ideas? I'm using apache, mod_perl and Embperl built from
tarball sources.

Thanks!

Neil

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Question re preloading embperl and apache shutdown [ In reply to ]
Hi Neil,

> I am now using Apache2.2, mod_perl 2 and Embperl 2.3. I am also
> preloading my Embperl code via startup.pl, and finding that
> "apachectl
> stop" seems to call my preload routine even when shutting
> down apache,
> which makes it take an absurdly long time to cycle the server when I
> change code. This didn't use to happen with apache1.3. Is
> anyone aware
> of a way to detect from within startup.pl whether we are
> starting up or
> shutting down? Then I guess I could skip the preload myself if we're
> stopping... any ideas? I'm using apache, mod_perl and Embperl
> built from
> tarball sources.

A start in apache is actually a start+restart IIRC. Could that be what
you're seeing? I posted this a few days back but perhaps it was lost in
the noise. I've got the following in my startup.pl:

use Apache2::ServerUtil;
# We want to do this only when the sever restarts. (The start process
# includes a restart). The below variable has a value of 1 during
# server start/stop and a value greater than one during the second
# phase of server starting and any graceful restart.
if ( Apache2::ServerUtil::restart_count() > 1 ) {
# force load/initialise perl stuff
}

Are any of the following useful to you (even if you set a variable using
the shutdown callback to forcibly stop the preload?) in
Apache2::ServerUtil?

# register server shutdown callback
Apache2::ServerUtil::server_shutdown_register_cleanup(sub {
Apache2::Const::OK });

# do something only when the server restarts
my $cnt = Apache2::ServerUtil::restart_count();
do_something_once() if $cnt > 1;

Cheers,

Andrew


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Question re preloading embperl and apache shutdown [ In reply to ]
Andrew O'Brien wrote:
> Hi Neil,
>
> A start in apache is actually a start+restart IIRC. Could that be what
> you're seeing? I posted this a few days back but perhaps it was lost in
> the noise. I've got the following in my startup.pl:
>
> use Apache2::ServerUtil;
> # We want to do this only when the sever restarts. (The start process
> # includes a restart). The below variable has a value of 1 during
> # server start/stop and a value greater than one during the second
> # phase of server starting and any graceful restart.
> if ( Apache2::ServerUtil::restart_count() > 1 ) {
> # force load/initialise perl stuff
> }
>
> Are any of the following useful to you (even if you set a variable using
> the shutdown callback to forcibly stop the preload?) in
> Apache2::ServerUtil?
>
> # register server shutdown callback
> Apache2::ServerUtil::server_shutdown_register_cleanup(sub {
> Apache2::Const::OK });
>
> # do something only when the server restarts
> my $cnt = Apache2::ServerUtil::restart_count();
> do_something_once() if $cnt > 1;

Thanks, Andrew, that's very useful. I have added the test for
restart_count(), and the server starts up a lot faster. I guess I was
preloading twice or something. However, it hasn't changed the length of
time the server takes to shutdown. I don't think it's actually calling
the startup.pl code to do this... I'm not sure what it's doing.
Basically I call "apachectl_perl stop" (this is for the mod_perl
backend, I build two versions - one for backend mod_perl, and
httpd_proxy for reverse proxy). When I do this, most of the httpd_perl
processes go away, but one is left hanging there for about 20 seconds.
In the meantime, I cannot restart, because the port is in use. I do seem
to remember when I was having issues with Embperl processing my TABLE
and TR tags, then those errors would appear again when I issued the stop
command. I believe this is what led me to believe that the startup is
being called at shutdown too. But now I don't think so - at least, not
my code. I am wondering now if Embperl is maybe doing the preload itself
again, internally, at shutdown. I'll try to look into it some more,
maybe do some tracing via logging to see what's going on. Meantime, I am
still fighting fires with my recent server upgrade - Embperl 2.3 has
royally screwed up my forms handling, it seems. Apparently fdat is being
handled differently with respect to setting variables in the code which
were previously then included in [$ hidden $], but no more. I really
thought Embperl 2 would be more stable by this point!

Thanks again,

Neil

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: Question re preloading embperl and apache shutdown [ In reply to ]
Andrew O'Brien wrote:
> Hi Neil,
> use Apache2::ServerUtil;
> # We want to do this only when the sever restarts. (The start process
> # includes a restart). The below variable has a value of 1 during
> # server start/stop and a value greater than one during the second
> # phase of server starting and any graceful restart.
> if ( Apache2::ServerUtil::restart_count() > 1 ) {
> # force load/initialise perl stuff
> }
>
> Are any of the following useful to you (even if you set a variable using
> the shutdown callback to forcibly stop the preload?) in
> Apache2::ServerUtil?
>
> # register server shutdown callback
> Apache2::ServerUtil::server_shutdown_register_cleanup(sub {
> Apache2::Const::OK });
>
> # do something only when the server restarts
> my $cnt = Apache2::ServerUtil::restart_count();
> do_something_once() if $cnt > 1;

Apparently Embperl isn't simply calling the preload routine again at
shutdown... for some reason, the httpd daemon is just sitting there
hanging for 30 seconds or so at shutdown. I tried tracing to a log file,
and the PreLoadFiles routine in Embperl wasn't being executed again at
shutdown. So I don't know why the server hangs like that rather than
just shutting down. It's got something to do with Embperl, though,
because when I switch preloading off, it shuts down very quickly with no
hang on that last process. A mystery.

Neil

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Question re preloading embperl and apache shutdown [ In reply to ]
On Thu, 24 Jul 2008, Andrew O'Brien wrote:
> A start in apache is actually a start+restart IIRC. Could that be what
> you're seeing? I posted this a few days back but perhaps it was lost
> in the noise. I've got the following in my startup.pl:
>
> use Apache2::ServerUtil;
> # We want to do this only when the sever restarts. (The start process
> # includes a restart). The below variable has a value of 1 during
> # server start/stop and a value greater than one during the second
> # phase of server starting and any graceful restart.
> if ( Apache2::ServerUtil::restart_count() > 1 ) {
> # force load/initialise perl stuff
> }
>
> Are any of the following useful to you (even if you set a variable
> using the shutdown callback to forcibly stop the preload?) in
> Apache2::ServerUtil?
>
> # register server shutdown callback
> Apache2::ServerUtil::server_shutdown_register_cleanup(sub {
> Apache2::Const::OK });
>
> # do something only when the server restarts
> my $cnt = Apache2::ServerUtil::restart_count();
> do_something_once() if $cnt > 1;

I suspect you probably mean

> do_something_once() if $cnt == 1;

Otherwise, you're depending upon the double start behavior, which could
cause problems when someone decides to fix that bug.

Ed

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
RE: Question re preloading embperl and apache shutdown [ In reply to ]
Hi Ed,

> > Are any of the following useful to you (even if you set a variable
> > using the shutdown callback to forcibly stop the preload?) in
> > Apache2::ServerUtil?
> >
> > # register server shutdown callback
> > Apache2::ServerUtil::server_shutdown_register_cleanup(sub {
> > Apache2::Const::OK });
> >
> > # do something only when the server restarts
> > my $cnt = Apache2::ServerUtil::restart_count();
> > do_something_once() if $cnt > 1;
>
> I suspect you probably mean
>
> > do_something_once() if $cnt == 1;
>
> Otherwise, you're depending upon the double start behavior,
> which could
> cause problems when someone decides to fix that bug.

Sorry, not a bug: That's taken directly from perldoc
Apache2::ServerUtil. See the full doco and use cases at
http://perl.apache.org/docs/2.0/api/Apache2/ServerUtil.html#C_restart_co
unt_

Documentation on the deliberate restart:
http://perl.apache.org/docs/2.0/user/handlers/server.html#Server_Life_Cy
cle

"Apache 2.0 starts by parsing the configuration file. After the
configuration file is parsed, the PerlOpenLogsHandler handlers are
executed if any. After that it's a turn of PerlPostConfigHandler
handlers to be run. When the post_config phase is finished the server
immediately restarts, to make sure that it can survive graceful restarts
after starting to serve the clients."

For further info see the above documentation sections and the 1.0 to 2.0
porting guide: http://perl.apache.org/docs/2.0/user/porting/compat.html

Cheers,

Andrew


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org