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 Andrej van der Zee <an...@gmail.com> on 2008/12/22 13:43:24 UTC
process initialisation in prefork-MPM
Hi,
I need to initialise some structures for each process (in prefork MPM)
when it is created, and need to be able to access these structures in
ap_hook_post_read_request and ap_hook_log_transaction handlers. I
would like to initialise the structures before the first HTTP request
is being served by the process. How should I do this?
Thank you,
Andrej
--
Andrej van der Zee
2-40-19 Koenji-minami
Suginami-ku, Tokyo
166-0003 JAPAN
Mobile: +81-(0)80-65251092
Phone/Fax: +81-(0)3-3318-3155
Re: process initialisation in prefork-MPM
Posted by Saju Pillai <sa...@gmail.com>.
On 22-Dec-08, at 6:49 PM, Andrej van der Zee wrote:
> Hi,
>
>>
>> You hook child_init (ap_hook_child_init) and store your data in
>> global
>> variables that are accessed by post_read_request and log_transaction.
>>
>
> BTW, in a worker-MPM, is child_init executed for every created
> worker-thread? Or is it per process?
iirc per process
-srp
>
> Thank you,
> Andrej
Re: process initialisation in prefork-MPM
Posted by Andrej van der Zee <an...@gmail.com>.
Hi,
>
> You hook child_init (ap_hook_child_init) and store your data in global
> variables that are accessed by post_read_request and log_transaction.
>
BTW, in a worker-MPM, is child_init executed for every created
worker-thread? Or is it per process?
Thank you,
Andrej
Re: process initialisation in prefork-MPM
Posted by Andrej van der Zee <an...@gmail.com>.
Hi,
>
> Global variables are fine if your module will never run multithreaded, or
> you won't write to the data structures from any potentially threaded
> situation.
>
> If you want to be able to run multithreaded, you can mutex access to the
> globals. If you want to decide at runtime, you can find out if you're
> threaded using ap_mpm_query().
>
Thanks, that is clear.
The thing is that in case of a worker-MPM I need to do initialisation
for every thread: Right after a worker thread is created, I need to do
a one-time initialisation for that thread. Though, I understood that
child_init() hooks after process-creation instead. Is there a way to
hook after thread-creation?
Cheers,
Andrej
Re: process initialisation in prefork-MPM
Posted by Sander Temme <sc...@apache.org>.
On Dec 22, 2008, at 4:48 AM, Sorin Manolache wrote:
> You hook child_init (ap_hook_child_init) and store your data in global
> variables that are accessed by post_read_request and log_transaction.
Global variables are fine if your module will never run multithreaded,
or you won't write to the data structures from any potentially
threaded situation.
If you want to be able to run multithreaded, you can mutex access to
the globals. If you want to decide at runtime, you can find out if
you're threaded using ap_mpm_query().
S.
--
Sander Temme
sctemme@apache.org
PGP FP: 51B4 8727 466A 0BC3 69F4 B7B8 B2BE BC40 1529 24AF
Re: process initialisation in prefork-MPM
Posted by Joe Lewis <jo...@joe-lewis.com>.
ricardo13 wrote:
> hi,
>
> For example, That's right ??
>
> #include <httpd.h>
> static int global_variable;
>
> static int init_child(request *r)
> {
> printf("HEllo World");
> }
>
> static void register_hooks(apr_pool_t *pool)
> {
> ap_hook_child_init(init_child, NULL, NULL, APR_HOOK_MIDDLE);
> }
>
> /* the main config structure */
> module AP_MODULE_DECLARE_DATA teste_module = {
> STANDARD20_MODULE_STUFF,
> NULL, /* create per-dir config structures */
> NULL, /* merge per-dir config structures */
> NULL, /* create per-server config structures */
> NULL, /* merge per-server config structures */
> NULL, /* table of config file commands */
> register_hooks /* register hooks */
> };
>
> I was using post_config, but now I changes for child_init.
>
> THank you
> Ricardo
>
>
>
> Joe Lewis-2 wrote:
>
>> ricardo13 wrote:
>>
>>> HI,
>>>
>>> Sorry, but I'm using Worker MPM.
>>> How do I declare variable using Worker MPM ?
>>>
>>>
>>> Thank you
>>> Ricardo
>>>
>>>
>> I always suggest the same method, regardless of the MPM, for
>> configuration options. If you absolutely don't want to use shared memory
>> and you use the worker MPM (threaded), you should be able to declare a
>> regular variable with your programming language of choice as static
>> variable, and don't reset it on a post_config unless it is only the
>> first time post_config is being run (otherwise, as a thread is killed
>> and started, it could reset your variable).
>>
>> --
>> Joe Lewis
>> Chief Nerd SILVERHAWK <http://www.silverhawk.net/> (801) 660-1900
>>
>> ------------------------------------------------------------------------
>> /An army is stengthened by labor and enervated by idleness.
>> --Vegetius, A.D. 4th Century/
>>
>>
>>
>
>
That is the idea. I've always preferred post_config() myself.
--
Joe Lewis
Chief Nerd SILVERHAWK <http://www.silverhawk.net/> (801) 660-1900
------------------------------------------------------------------------
/It's amazing that fans want to see me play. It's kind of scary. I guess
that's what is wrong with our society.
-- John Kruk on being chosen to the 1993 All-Star team/
Re: process initialisation in prefork-MPM
Posted by ricardo13 <ri...@gmail.com>.
hi,
For example, That's right ??
#include <httpd.h>
static int global_variable;
static int init_child(request *r)
{
printf("HEllo World");
}
static void register_hooks(apr_pool_t *pool)
{
ap_hook_child_init(init_child, NULL, NULL, APR_HOOK_MIDDLE);
}
/* the main config structure */
module AP_MODULE_DECLARE_DATA teste_module = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
NULL, /* table of config file commands */
register_hooks /* register hooks */
};
I was using post_config, but now I changes for child_init.
THank you
Ricardo
Joe Lewis-2 wrote:
>
> ricardo13 wrote:
>> HI,
>>
>> Sorry, but I'm using Worker MPM.
>> How do I declare variable using Worker MPM ?
>>
>>
>> Thank you
>> Ricardo
>>
>
> I always suggest the same method, regardless of the MPM, for
> configuration options. If you absolutely don't want to use shared memory
> and you use the worker MPM (threaded), you should be able to declare a
> regular variable with your programming language of choice as static
> variable, and don't reset it on a post_config unless it is only the
> first time post_config is being run (otherwise, as a thread is killed
> and started, it could reset your variable).
>
> --
> Joe Lewis
> Chief Nerd SILVERHAWK <http://www.silverhawk.net/> (801) 660-1900
>
> ------------------------------------------------------------------------
> /An army is stengthened by labor and enervated by idleness.
> --Vegetius, A.D. 4th Century/
>
>
--
View this message in context: http://www.nabble.com/process-initialisation-in-prefork-MPM-tp21127165p24686966.html
Sent from the Apache HTTP Server - Module Writers mailing list archive at Nabble.com.
Re: process initialisation in prefork-MPM
Posted by Joe Lewis <jo...@joe-lewis.com>.
ricardo13 wrote:
> HI,
>
> Sorry, but I'm using Worker MPM.
> How do I declare variable using Worker MPM ?
>
>
> Thank you
> Ricardo
>
I always suggest the same method, regardless of the MPM, for
configuration options. If you absolutely don't want to use shared memory
and you use the worker MPM (threaded), you should be able to declare a
regular variable with your programming language of choice as static
variable, and don't reset it on a post_config unless it is only the
first time post_config is being run (otherwise, as a thread is killed
and started, it could reset your variable).
--
Joe Lewis
Chief Nerd SILVERHAWK <http://www.silverhawk.net/> (801) 660-1900
------------------------------------------------------------------------
/An army is stengthened by labor and enervated by idleness.
--Vegetius, A.D. 4th Century/
Re: process initialisation in prefork-MPM
Posted by ricardo13 <ri...@gmail.com>.
HI,
Sorry, but I'm using Worker MPM.
How do I declare variable using Worker MPM ?
Thank you
Ricardo
Joe Lewis-2 wrote:
>
> If only you had read the signature of the e-mail you just responded to
> regarding top-posting, your question would have appeared below the
> thread indicating that it does belong in this thread.
>
> ricardo13 wrote:
>> HI,
>>
>> One question.
>> How do I declare global variables ??
>>
>> Thank you
>> Ricardo
>>
>>
>>
>> Sorin Manolache wrote:
>>
>>> On 2008-12-22, Andrej van der Zee <an...@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> I need to initialise some structures for each process (in prefork MPM)
>>>> when it is created, and need to be able to access these structures in
>>>> ap_hook_post_read_request and ap_hook_log_transaction handlers. I
>>>> would like to initialise the structures before the first HTTP request
>>>> is being served by the process. How should I do this?
>>>>
>>> You hook child_init (ap_hook_child_init) and store your data in global
>>> variables that are accessed by post_read_request and log_transaction.
>>>
>>> S
>>>
>>> --
>>> A: Because it reverses the logical flow of conversation.
>>> Q: Why is top-posting frowned upon?
>>> A: Top-posting.
>>> Q: What is the most annoying thing in e-mail?
>>>
>>>
>>>
>>
>>
>
> Here we go. Global variables. In the prefork MPM, you are going to have
> to use shared memory segments. When you start, the first time you run
> your post config, create a shared memory segment. Then, on the other
> post configs (from inside of each process), attach to the shared memory
> handle, and set a "local" variable to your shared memory structure.
>
> Joe
> --
> Joe Lewis
> Chief Nerd SILVERHAWK <http://www.silverhawk.net/> (801) 660-1900
>
> ------------------------------------------------------------------------
> /Honolulu - it's got everything. Sand for the children, sun for the
> wife, sharks for the wife's mother.
> --Ken Dodd/
>
>
--
View this message in context: http://www.nabble.com/process-initialisation-in-prefork-MPM-tp21127165p24686596.html
Sent from the Apache HTTP Server - Module Writers mailing list archive at Nabble.com.
Re: process initialisation in prefork-MPM
Posted by Joe Lewis <jo...@joe-lewis.com>.
If only you had read the signature of the e-mail you just responded to
regarding top-posting, your question would have appeared below the
thread indicating that it does belong in this thread.
ricardo13 wrote:
> HI,
>
> One question.
> How do I declare global variables ??
>
> Thank you
> Ricardo
>
>
>
> Sorin Manolache wrote:
>
>> On 2008-12-22, Andrej van der Zee <an...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I need to initialise some structures for each process (in prefork MPM)
>>> when it is created, and need to be able to access these structures in
>>> ap_hook_post_read_request and ap_hook_log_transaction handlers. I
>>> would like to initialise the structures before the first HTTP request
>>> is being served by the process. How should I do this?
>>>
>> You hook child_init (ap_hook_child_init) and store your data in global
>> variables that are accessed by post_read_request and log_transaction.
>>
>> S
>>
>> --
>> A: Because it reverses the logical flow of conversation.
>> Q: Why is top-posting frowned upon?
>> A: Top-posting.
>> Q: What is the most annoying thing in e-mail?
>>
>>
>>
>
>
Here we go. Global variables. In the prefork MPM, you are going to have
to use shared memory segments. When you start, the first time you run
your post config, create a shared memory segment. Then, on the other
post configs (from inside of each process), attach to the shared memory
handle, and set a "local" variable to your shared memory structure.
Joe
--
Joe Lewis
Chief Nerd SILVERHAWK <http://www.silverhawk.net/> (801) 660-1900
------------------------------------------------------------------------
/Honolulu - it's got everything. Sand for the children, sun for the
wife, sharks for the wife's mother.
--Ken Dodd/
Re: process initialisation in prefork-MPM
Posted by ricardo13 <ri...@gmail.com>.
HI,
One question.
How do I declare global variables ??
Thank you
Ricardo
Sorin Manolache wrote:
>
> On 2008-12-22, Andrej van der Zee <an...@gmail.com> wrote:
>> Hi,
>>
>> I need to initialise some structures for each process (in prefork MPM)
>> when it is created, and need to be able to access these structures in
>> ap_hook_post_read_request and ap_hook_log_transaction handlers. I
>> would like to initialise the structures before the first HTTP request
>> is being served by the process. How should I do this?
>
> You hook child_init (ap_hook_child_init) and store your data in global
> variables that are accessed by post_read_request and log_transaction.
>
> S
>
> --
> A: Because it reverses the logical flow of conversation.
> Q: Why is top-posting frowned upon?
> A: Top-posting.
> Q: What is the most annoying thing in e-mail?
>
>
--
View this message in context: http://www.nabble.com/process-initialisation-in-prefork-MPM-tp21127165p24686243.html
Sent from the Apache HTTP Server - Module Writers mailing list archive at Nabble.com.
Re: process initialisation in prefork-MPM
Posted by Andrej van der Zee <an...@gmail.com>.
>
> You hook child_init (ap_hook_child_init) and store your data in global
> variables that are accessed by post_read_request and log_transaction.
>
Easy enough.
Thanks,
Andrej
Re: process initialisation in prefork-MPM
Posted by Sorin Manolache <so...@gmail.com>.
On 2008-12-22, Andrej van der Zee <an...@gmail.com> wrote:
> Hi,
>
> I need to initialise some structures for each process (in prefork MPM)
> when it is created, and need to be able to access these structures in
> ap_hook_post_read_request and ap_hook_log_transaction handlers. I
> would like to initialise the structures before the first HTTP request
> is being served by the process. How should I do this?
You hook child_init (ap_hook_child_init) and store your data in global
variables that are accessed by post_read_request and log_transaction.
S
--
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?