You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by S�bastien Bonnegent <sb...@mediapps.com> on 2002/08/21 16:11:32 UTC
How can I use a data structure shared by all the httpd process ?
Hi,
My purpose is sharing a data structure.
For example with an array:
- httpd creation, my_array is empty
- there are 8 servers launched
- server1 add an entry named (X)
- server5 add an entry
- server3 read an entry
- server7 remove the (X) entry
After this, my_array contains one line which is the server5 entry.
For the moment, I use a "apr_array_header_t * my_array" and I put
it in httpd.h.
My problem is :
each server process access to a copy of the array, so they
could not share data..
Example:
server1 array contains 0 element
server2 array contains 3 elements
server3 ....
But, I want :
an unique array
Example:
server1 ----\
server2 -----\
server3 ------\
server4 ----------> contains X elements
...
Please, could someone give me a solution ?
sinad
--
GPG uid: 0xCB92591D ICQ: 60143970
LINUX - because life is too short to reboot !
-- Fortune:
Never give an inch!
Re: Do you know apr_anylock_t ?
Posted by Aaron Bannert <aa...@clove.org>.
On Thu, Aug 22, 2002 at 02:38:50PM +0200, Sébastien Bonnegent wrote:
> sure, to lock the shared memory area, I have to use the apr_anylock_t structure
> but I haven't found documentation on the different lock type...
> and it seems that this structure is not very used in the apache source...
There is only one type of shared memory in APR: apr_shm.h. It allows you
to request regions of shared memory to use between httpd children. If
you know the sizes of the structures you will store in there, you can
treat it like a big array or a big blob of memory. If OTOH you need to
do memory allocation and deallocation inside of that block, then you
can use the apr_rmm.h interface to manage that memory.
> Are there someone who know the different lock type ?
There are three types of locks. If you are using shared memory and
you want it to protect you whether you're using the prefork or worker
MPM, then the only one you should use is apr_global_mutex.h. The
apr_anylock_t structure is an abstraction of all the apr lock types,
and is only necessary for telling the apr_rmm.h interface how it
should protect its internal structures.
[If you have more questions, feel free to follow this up on the
dev@apr.apache.org list.]
-aaron
Re: Do you know apr_anylock_t ?
Posted by Aaron Bannert <aa...@clove.org>.
On Thu, Aug 22, 2002 at 02:38:50PM +0200, Sébastien Bonnegent wrote:
> sure, to lock the shared memory area, I have to use the apr_anylock_t structure
> but I haven't found documentation on the different lock type...
> and it seems that this structure is not very used in the apache source...
There is only one type of shared memory in APR: apr_shm.h. It allows you
to request regions of shared memory to use between httpd children. If
you know the sizes of the structures you will store in there, you can
treat it like a big array or a big blob of memory. If OTOH you need to
do memory allocation and deallocation inside of that block, then you
can use the apr_rmm.h interface to manage that memory.
> Are there someone who know the different lock type ?
There are three types of locks. If you are using shared memory and
you want it to protect you whether you're using the prefork or worker
MPM, then the only one you should use is apr_global_mutex.h. The
apr_anylock_t structure is an abstraction of all the apr lock types,
and is only necessary for telling the apr_rmm.h interface how it
should protect its internal structures.
[If you have more questions, feel free to follow this up on the
dev@apr.apache.org list.]
-aaron
Do you know apr_anylock_t ?
Posted by S�bastien Bonnegent <sb...@mediapps.com>.
Ian Holsman wrote:
IH> Sébastien Bonnegent wrote:
IH> > Hi,
IH> >
IH> > My purpose is sharing a data structure.
IH> > For example with an array:
IH> > - httpd creation, my_array is empty
IH> > - there are 8 servers launched
IH> > - server1 add an entry named (X)
IH> > - server5 add an entry
IH> > - server3 read an entry
IH> > - server7 remove the (X) entry
IH> > After this, my_array contains one line which is the server5 entry.
IH> >
IH> you will need to create a shared memory area to put your structure in,
IH> and have some kind of locking mechanism to ensure you don't have any
IH> race conditions.
sure, to lock the shared memory area, I have to use the apr_anylock_t structure
but I haven't found documentation on the different lock type...
and it seems that this structure is not very used in the apache source...
Are there someone who know the different lock type ?
IH> have a look at apr-utils/misc/apr_rmm.c & apr_queue.c for an idea on
IH> what it required.
thank you. I haven't found apr_queue.c but apr_rmm.c is perfect.
seß - sinad
--
GPG uid: 0xCB92591D ICQ: 60143970
LINUX - because life is too short to reboot !
-- Fortune:
Q: Why should you always serve a Southern Carolina football man
soup in a plate?
A: 'Cause if you give him a bowl, he'll throw it away.
Re: How can I use a data structure shared by all the httpd process ?
Posted by Eric Prud'hommeaux <er...@w3.org>.
On Wed, Aug 21, 2002 at 08:06:41AM -0700, Ian Holsman wrote:
> Sébastien Bonnegent wrote:
> > Hi,
> >
> > My purpose is sharing a data structure.
> > For example with an array:
> > - httpd creation, my_array is empty
> > - there are 8 servers launched
> > - server1 add an entry named (X)
> > - server5 add an entry
> > - server3 read an entry
> > - server7 remove the (X) entry
> > After this, my_array contains one line which is the server5 entry.
> >
> you will need to create a shared memory area to put your structure in,
> and have some kind of locking mechanism to ensure you don't have any
> race conditions.
>
> have a look at apr-utils/misc/apr_rmm.c & apr_queue.c for an idea on
> what it required.
If you are playing with shmem on a linux box, you will probably need
to manually free segments from time to time.
# ipcs -m
key shmid owner perms bytes nattch status
0x00000000 12345 www-data 600 92164 0 dest
will give you the list of share memory segments in use. The "nattch"
field gives you the ref count.
iprm shm 12345
will free up that memory segment so it can be re-attached.
> > For the moment, I use a "apr_array_header_t * my_array" and I put
> > it in httpd.h.
> >
> > My problem is :
> > each server process access to a copy of the array, so they
> > could not share data..
> > Example:
> > server1 array contains 0 element
> > server2 array contains 3 elements
> > server3 ....
> >
> > But, I want :
> > an unique array
> > Example:
> > server1 ----\
> > server2 -----\
> > server3 ------\
> > server4 ----------> contains X elements
> > ...
> >
> > Please, could someone give me a solution ?
> >
> > sinad
>
--
-eric
(eric@w3.org)
Feel free to forward this message to any list for any purpose other than
email address distribution.
Re: How can I use a data structure shared by all the httpd process
?
Posted by Ian Holsman <ia...@apache.org>.
Sébastien Bonnegent wrote:
> Hi,
>
> My purpose is sharing a data structure.
> For example with an array:
> - httpd creation, my_array is empty
> - there are 8 servers launched
> - server1 add an entry named (X)
> - server5 add an entry
> - server3 read an entry
> - server7 remove the (X) entry
> After this, my_array contains one line which is the server5 entry.
>
you will need to create a shared memory area to put your structure in,
and have some kind of locking mechanism to ensure you don't have any
race conditions.
have a look at apr-utils/misc/apr_rmm.c & apr_queue.c for an idea on
what it required.
> For the moment, I use a "apr_array_header_t * my_array" and I put
> it in httpd.h.
>
> My problem is :
> each server process access to a copy of the array, so they
> could not share data..
> Example:
> server1 array contains 0 element
> server2 array contains 3 elements
> server3 ....
>
> But, I want :
> an unique array
> Example:
> server1 ----\
> server2 -----\
> server3 ------\
> server4 ----------> contains X elements
> ...
>
> Please, could someone give me a solution ?
>
> sinad