You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Micha Lenk <mi...@lenk.info> on 2013/02/05 18:12:09 UTC

Documentation on mod_slotmem_shm

Hi all,

I am currently working on an Apache module that needs to maintain some 
shared data that is used by all requests, on all workers. This data does 
not need to be persistent, so I thought about using shared memory for 
this task. Someone pointed me to mod_slotmem_shm (hi Rainer), but now I 
am a bit lost on how to use it.

Does anybody have a pointer to documentation or example source code on 
how to use mod_slotmem_shm? Any suggestions are welcome.

Regards,
Micha

Re: Documentation on mod_slotmem_shm

Posted by Rainer Jung <ra...@kippdata.de>.
On 06.02.2013 17:28, Micha Lenk wrote:
> On 02/05/2013 08:04 PM CEST +02:00, Rainer Jung wrote:
>> Example code using it: modules/cluster/mod_heartmonitor.c should be
>> simplest, look for slotmem and SLOTMEM in there. That should at least
>> show how to bootstrap and use slotmem.
> 
> Okay, the longer I am reading anything related to mod_slotmem_shm, the
> more I get the impression that it is the wrong tool for my task. If I
> understood it correctly, mod_slotmem_shm organizes data in slots. This
> appears to make it unnecessarily limited to the number of slots I
> initialize it with.
> 
> What I need is a way to transfer information from one long living
> request to another entirely independent request some time later. The
> first request contains a cookie (i.e. a random string), which is also
> contained in the second request. I would like to use this cookie as a
> handle to store some data (fixed size, if needed) generated during
> processing of the first request somewhere (at least for the life time of
> the first request). The second request then needs to be able to use the
> cookie to access the data the first request already generated. Moreover,
> an arbitrary number of such request pairs can happen at the same time.
> 
> Given the requirements above, is the mod_slotmem_shm API still the right
> tool for this purpose?
> 
> I just started looking at mod_socache_shmcb -- is this maybe better
> suited for the purpose described above?
> 
> I could also go for a custom shared memory usage implementation, but I
> thought making use of any already existing API might be a better idea
> (trying avoid implementing things twice). So, any hint is appreciated...

It seems socache is a better choice in your case. slotmem is based on a
fixed max. number of cache entries, each of fixed size and accessed by
an integer key.

For socache you can find some info in

include/ap_socache.h

and a probably not to complex example is

modules/aaa/mod_authn_socache.c

It comes with four different implementations (providers), the shmcb one
is probably the one you'd use (or the memcached based one if sharing in
a farm of hosts is needed).

Regards,

Rainer

Re: Documentation on mod_slotmem_shm

Posted by Micha Lenk <mi...@lenk.info>.
Hi Rainer,

On 02/05/2013 08:04 PM CEST +02:00, Rainer Jung wrote:
> Example code using it: modules/cluster/mod_heartmonitor.c should be
> simplest, look for slotmem and SLOTMEM in there. That should at least
> show how to bootstrap and use slotmem.

Okay, the longer I am reading anything related to mod_slotmem_shm, the 
more I get the impression that it is the wrong tool for my task. If I 
understood it correctly, mod_slotmem_shm organizes data in slots. This 
appears to make it unnecessarily limited to the number of slots I 
initialize it with.

What I need is a way to transfer information from one long living 
request to another entirely independent request some time later. The 
first request contains a cookie (i.e. a random string), which is also 
contained in the second request. I would like to use this cookie as a 
handle to store some data (fixed size, if needed) generated during 
processing of the first request somewhere (at least for the life time of 
the first request). The second request then needs to be able to use the 
cookie to access the data the first request already generated. Moreover, 
an arbitrary number of such request pairs can happen at the same time.

Given the requirements above, is the mod_slotmem_shm API still the right 
tool for this purpose?

I just started looking at mod_socache_shmcb -- is this maybe better 
suited for the purpose described above?

I could also go for a custom shared memory usage implementation, but I 
thought making use of any already existing API might be a better idea 
(trying avoid implementing things twice). So, any hint is appreciated...

Regards,
Micha

Re: Documentation on mod_slotmem_shm

Posted by Rainer Jung <ra...@kippdata.de>.
On 05.02.2013 18:12, Micha Lenk wrote:
> Hi all,
> 
> I am currently working on an Apache module that needs to maintain some
> shared data that is used by all requests, on all workers. This data does
> not need to be persistent, so I thought about using shared memory for
> this task. Someone pointed me to mod_slotmem_shm (hi Rainer), but now I
> am a bit lost on how to use it.
> 
> Does anybody have a pointer to documentation or example source code on
> how to use mod_slotmem_shm? Any suggestions are welcome.

I'd say a short overview is in:

http://httpd.apache.org/docs/2.4/en/mod/mod_slotmem_shm.html

and

include/ap_slotmem.h

Example code using it: modules/cluster/mod_heartmonitor.c should be
simplest, look for slotmem and SLOTMEM in there. That should at least
show how to bootstrap and use slotmem.

Regards,

Rainer