You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Brian Kim <09...@gmail.com> on 2009/06/24 21:47:26 UTC
[users@httpd] global variable use in mod_proxy_http.c
Hi. All.
In mod_proxy_http.c, I globally declared a variable, like unsiged int count = 0;
And I make it increase whenever the proxy gets a new http request.
I expect it increases like 1, 2, 3, 4,... but it is always same 1.
Does anydoby know why this happens? How can I use a global variable in
mod_proxy_http?
I am really new to this proxy stuff. I hope somebody can anwser to my
simple question.
Thanks.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] global variable use in mod_proxy_http.c
Posted by Sander Temme <sc...@apache.org>.
On Jun 24, 2009, at 12:47 PM, Brian Kim wrote:
> In mod_proxy_http.c, I globally declared a variable, like unsiged
> int count = 0;
>
> And I make it increase whenever the proxy gets a new http request.
You mean when your httpd child processes get a new http request.
> I expect it increases like 1, 2, 3, 4,... but it is always same 1.
How many test requests did you use, did you touch all the children?
> Does anydoby know why this happens? How can I use a global variable in
> mod_proxy_http?
Declare it as shared memory, or extend the existing Scoreboard. See
mod_example_ipc.c for the former.
http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/examples/mod_example_ipc.c?view=co
> I am really new to this proxy stuff. I hope somebody can anwser to my
> simple question.
S.
--
Sander Temme
sctemme@apache.org
PGP FP: 51B4 8727 466A 0BC3 69F4 B7B8 B2BE BC40 1529 24AF
Re: [users@httpd] global variable use in mod_proxy_http.c
Posted by Brian Kim <09...@gmail.com>.
Thanks to Sander & André, I clearly understood why it happened and how
I can get it over.
Now I am looking at an example,.mod_example_ipc.c, to use a shared
memory space.
Thanks again.
On Wed, Jun 24, 2009 at 5:31 PM, André Warnier<aw...@ice-sa.com> wrote:
> Brian Kim wrote:
>>
>> Hi. All.
>>
>> In mod_proxy_http.c, I globally declared a variable, like unsiged int
>> count = 0;
>>
>> And I make it increase whenever the proxy gets a new http request.
>>
>> I expect it increases like 1, 2, 3, 4,... but it is always same 1.
>>
>> Does anydoby know why this happens? How can I use a global variable in
>> mod_proxy_http?
>>
> Not a simple answer, but read this :
> http://marc.info/?l=apache-httpd-users&m=124467015611975&w=2
>
> The basic point is : when it starts, Apache is a single process. That one
> loads mod_proxy, with your variable initialised to 0.
> Then that main Apache forks into children. Each child is an exact copy,
> thus also with the variable = 0.
> The main Apache does not serve requests, so its copy always remains 0.
> But it distributes requests, 1 per child, as they come in.
> So probably your first request gets handled by child #1. It serves the
> request, and increments the variable, which for this child is now 1.
> Then your next request comes in, and is handled by child #2.
> Its variable is still 0. So it serves the request and increments the
> variable.
> Then your next request comes in and is served by child #3.
> And so on.
> Until... enough requests have come in, that a child that has been used
> before, gets re-used. Then the variable is at 1, and now becomes 2.
> But only in that child.
> And so on.
>
> Got it ?
>
> If you start your Apache with a maximum of 3 children e.g., then after 4
> requests you are guaranteed to see a 2.
>
> Morality : you have to find a place to store your counter, that is common to
> all children (or threads). And of course synchronise access to it.
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> " from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] global variable use in mod_proxy_http.c
Posted by André Warnier <aw...@ice-sa.com>.
Brian Kim wrote:
> Hi. All.
>
> In mod_proxy_http.c, I globally declared a variable, like unsiged int count = 0;
>
> And I make it increase whenever the proxy gets a new http request.
>
> I expect it increases like 1, 2, 3, 4,... but it is always same 1.
>
> Does anydoby know why this happens? How can I use a global variable in
> mod_proxy_http?
>
Not a simple answer, but read this :
http://marc.info/?l=apache-httpd-users&m=124467015611975&w=2
The basic point is : when it starts, Apache is a single process. That
one loads mod_proxy, with your variable initialised to 0.
Then that main Apache forks into children. Each child is an exact copy,
thus also with the variable = 0.
The main Apache does not serve requests, so its copy always remains 0.
But it distributes requests, 1 per child, as they come in.
So probably your first request gets handled by child #1. It serves the
request, and increments the variable, which for this child is now 1.
Then your next request comes in, and is handled by child #2.
Its variable is still 0. So it serves the request and increments the
variable.
Then your next request comes in and is served by child #3.
And so on.
Until... enough requests have come in, that a child that has been used
before, gets re-used. Then the variable is at 1, and now becomes 2.
But only in that child.
And so on.
Got it ?
If you start your Apache with a maximum of 3 children e.g., then after 4
requests you are guaranteed to see a 2.
Morality : you have to find a place to store your counter, that is
common to all children (or threads). And of course synchronise access
to it.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org