You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Peter Janovsky <pe...@yahoo.com> on 2011/01/10 23:16:43 UTC
module configuration kill
upon module initialization the registered configuration function is called. the
module calls the same configuration function upon stop/restart of the apache
httpd worker processes. the problem i'm experiencing is the variables within
the configuration struct i've specified for the module are reinitialized when
the configuration function is called upon stop/restart of the worker processes.
is there an internal event i can hook into to determine if the worker has been
stopped, restarted or in-the-process of crashing?
how do i go about preserving variable state specific to the individual worker?
thnx for all your help in advance - peter
Re: module configuration kill
Posted by Victor Ronin <vi...@gmail.com>.
I will do this probably on apr_hook_pre_connection.
> that is definitely of use. thank you. where would i call
> apr_pool_register_cleanup? originally i thought it would be in register_hooks
> or the server_configuration_callback but i've noticed these are called on start
> and stop of the Apache workers. thus calling the function in there would cause
> multiple callbacks to hold references to the workers. do i need an internal
> state variable which determines if this is the first time the
> server_configuration_callback was called?
>
>
>
> ________________________________
> From: Nick Kew<ni...@apache.org>
> To: modules-dev@httpd.apache.org
> Sent: Wed, January 12, 2011 3:15:07 PM
> Subject: Re: module configuration kill
>
> On Wed, 12 Jan 2011 11:24:36 -0800 (PST)
> Peter Janovsky<pe...@yahoo.com> wrote:
>
>> is it possible to hook into an event fired when the workers are shutdown,
> Any cleanup registered on the child pool will run when the child quits,
> if that's any use to you.
>
Antwort: using sockets within an apache module
Posted by pi...@mindlab.de.
Hi Peter!
It should no problem in general -- we are using sockets in different
modules. But you must take care of thread handling in Apache running as
worker because you might get hundreds of connections at the same time when
you have a socket per thread (perhaps a problem for your server
application). To avoid this we are using a connection pool per child
created with the APR resource list. Our implementation works for prefork
and worker so the Apache installation doesn't matter to us.
Pierre
Von:
Peter Janovsky <pe...@yahoo.com>
An:
modules-dev@httpd.apache.org
Datum:
21.01.2011 22:22
Betreff:
using sockets within an apache module
we have a requirement to pass content generated during a request to an
external
application. after researching the APR API, reading up on the Apache
module
architecture and through the help of this group we've decided to use
sockets
within each child process. with that said can anyone see a problem with
this
implementation in regards to the child process life cycle?
brief overview
- Apache running in prefork
- ap_hook_child_init initializes socket specific child process and
registers
pool cleanup for socket's associated memory pool where socket is closed
- ap_hook_handler will be responsible for writing to the socket
using sockets within an apache module
Posted by Peter Janovsky <pe...@yahoo.com>.
we have a requirement to pass content generated during a request to an external
application. after researching the APR API, reading up on the Apache module
architecture and through the help of this group we've decided to use sockets
within each child process. with that said can anyone see a problem with this
implementation in regards to the child process life cycle?
brief overview
- Apache running in prefork
- ap_hook_child_init initializes socket specific child process and registers
pool cleanup for socket's associated memory pool where socket is closed
- ap_hook_handler will be responsible for writing to the socket
Re: module configuration kill
Posted by Victor Ronin <vi...@gmail.com>.
Generally, this depends on what MPM module is used. MPM module can
implement some specific logic regarding childs.
You can take a look here: http://httpd.apache.org/docs/2.0/mpm.html
As I know most of MPM modules create a new process for a child, so each
child will have it's own global variables.
However, as example mpm_winnt has only one child, so you can disregard
all worries regarding keeping instances of variables in sync between
childs.
Regards,
Victor Ronin
There are three
> this is turning out to be exactly what i was searching for. quick question
> regarding variable initialization. if i declare a global variable and assign it
> a value within the child_init hook it appears that each child contains a
> separate instance of the variable. is this correct?
>
> i have tested this theory using the following
>
> int pid = 0;
>
> // registered handler for children
> static void child_handler(apr_pool_t *p, server_rec *s) {
> pid = (int)getpid();
> apr_pool_cleanup_register(p, (void *)s, pool_cleanup, child_cleanup);
> }
>
> // registered handler for HTTP methods
> static int method_handler(request_rec *r) {
> fprintf(stderr, "method_handler called for pid (%d)\n", (int)getpid());
> fprintf(stderr, "pid initialized within child_handler (%d)\n", pid);
> fflush(stderr);
> }
>
> // cleans up pool resources
> apr_status_t pool_cleanup(void *data) {
> fprintf(stderr, "pool_cleanup called for pid (%d)\n", (int)getpid());
> fflush(stderr);
> }
>
> // cleans up child resources
> apr_status_t authenticator_child_cleanup(void *data) {
> fprintf(stderr, "child_cleanup called for pid (%d)\n", (int)getpid());
> fflush(stderr);
> }
>
> // declares the handlers for other events
> static void register_hooks (apr_pool_t *p) {
> ap_hook_handler(method_handler, NULL, NULL, APR_HOOK_MIDDLE);
> ap_hook_child_init(child_handler, NULL, NULL, APR_HOOK_MIDDLE);
> }
>
>
>
> ________________________________
> From: Ben Noordhuis<in...@bnoordhuis.nl>
> To: modules-dev@httpd.apache.org
> Sent: Wed, January 12, 2011 5:11:32 PM
> Subject: Re: module configuration kill
>
> On Wed, Jan 12, 2011 at 22:56, Peter Janovsky<pe...@yahoo.com> wrote:
>> that is definitely of use. thank you. where would i call
>> apr_pool_register_cleanup? originally i thought it would be in register_hooks
> From your child_init hook. Register it with ap_hook_child_init() from
> your register_hooks function.
>
>
>
>
Re: module configuration kill
Posted by Peter Janovsky <pe...@yahoo.com>.
this is turning out to be exactly what i was searching for. quick question
regarding variable initialization. if i declare a global variable and assign it
a value within the child_init hook it appears that each child contains a
separate instance of the variable. is this correct?
i have tested this theory using the following
int pid = 0;
// registered handler for children
static void child_handler(apr_pool_t *p, server_rec *s) {
pid = (int)getpid();
apr_pool_cleanup_register(p, (void *)s, pool_cleanup, child_cleanup);
}
// registered handler for HTTP methods
static int method_handler(request_rec *r) {
fprintf(stderr, "method_handler called for pid (%d)\n", (int)getpid());
fprintf(stderr, "pid initialized within child_handler (%d)\n", pid);
fflush(stderr);
}
// cleans up pool resources
apr_status_t pool_cleanup(void *data) {
fprintf(stderr, "pool_cleanup called for pid (%d)\n", (int)getpid());
fflush(stderr);
}
// cleans up child resources
apr_status_t authenticator_child_cleanup(void *data) {
fprintf(stderr, "child_cleanup called for pid (%d)\n", (int)getpid());
fflush(stderr);
}
// declares the handlers for other events
static void register_hooks (apr_pool_t *p) {
ap_hook_handler(method_handler, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(child_handler, NULL, NULL, APR_HOOK_MIDDLE);
}
________________________________
From: Ben Noordhuis <in...@bnoordhuis.nl>
To: modules-dev@httpd.apache.org
Sent: Wed, January 12, 2011 5:11:32 PM
Subject: Re: module configuration kill
On Wed, Jan 12, 2011 at 22:56, Peter Janovsky <pe...@yahoo.com> wrote:
> that is definitely of use. thank you. where would i call
> apr_pool_register_cleanup? originally i thought it would be in register_hooks
>From your child_init hook. Register it with ap_hook_child_init() from
your register_hooks function.
Re: module configuration kill
Posted by Ben Noordhuis <in...@bnoordhuis.nl>.
On Wed, Jan 12, 2011 at 22:56, Peter Janovsky <pe...@yahoo.com> wrote:
> that is definitely of use. thank you. where would i call
> apr_pool_register_cleanup? originally i thought it would be in register_hooks
>From your child_init hook. Register it with ap_hook_child_init() from
your register_hooks function.
Re: module configuration kill
Posted by Peter Janovsky <pe...@yahoo.com>.
that is definitely of use. thank you. where would i call
apr_pool_register_cleanup? originally i thought it would be in register_hooks
or the server_configuration_callback but i've noticed these are called on start
and stop of the Apache workers. thus calling the function in there would cause
multiple callbacks to hold references to the workers. do i need an internal
state variable which determines if this is the first time the
server_configuration_callback was called?
________________________________
From: Nick Kew <ni...@apache.org>
To: modules-dev@httpd.apache.org
Sent: Wed, January 12, 2011 3:15:07 PM
Subject: Re: module configuration kill
On Wed, 12 Jan 2011 11:24:36 -0800 (PST)
Peter Janovsky <pe...@yahoo.com> wrote:
> is it possible to hook into an event fired when the workers are shutdown,
Any cleanup registered on the child pool will run when the child quits,
if that's any use to you.
--
Nick Kew
Available for work, contract or permanent.
http://www.webthing.com/~nick/cv.html
Re: module configuration kill
Posted by Nick Kew <ni...@apache.org>.
On Wed, 12 Jan 2011 11:24:36 -0800 (PST)
Peter Janovsky <pe...@yahoo.com> wrote:
> is it possible to hook into an event fired when the workers are shutdown,
Any cleanup registered on the child pool will run when the child quits,
if that's any use to you.
--
Nick Kew
Available for work, contract or permanent.
http://www.webthing.com/~nick/cv.html
Re: module configuration kill
Posted by Peter Janovsky <pe...@yahoo.com>.
is it possible to hook into an event fired when the workers are shutdown, if so
how? basically i am interested in the cleanup process modules enter when their
associated worker threads either crash or are stopped/restarted.
________________________________
From: Nick Kew <ni...@apache.org>
To: modules-dev@httpd.apache.org
Sent: Mon, January 10, 2011 6:43:42 PM
Subject: Re: module configuration kill
On Mon, 10 Jan 2011 14:16:43 -0800 (PST)
Peter Janovsky <pe...@yahoo.com> wrote:
> how do i go about preserving variable state specific to the individual worker?
On a restart, the old pools are cleaned up before reinitialisation starts.
So in your cleanups, you can reset any variables that need reinitialising
from a virgin state.
--
Nick Kew
Available for work, contract or permanent.
http://www.webthing.com/~nick/cv.html
Re: module configuration kill
Posted by Nick Kew <ni...@apache.org>.
On Mon, 10 Jan 2011 14:16:43 -0800 (PST)
Peter Janovsky <pe...@yahoo.com> wrote:
> how do i go about preserving variable state specific to the individual worker?
On a restart, the old pools are cleaned up before reinitialisation starts.
So in your cleanups, you can reset any variables that need reinitialising
from a virgin state.
--
Nick Kew
Available for work, contract or permanent.
http://www.webthing.com/~nick/cv.html