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 Oğuzhan TOPGÜL <og...@gmail.com> on 2011/11/22 10:26:27 UTC

basic example shared memory code

Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
example shared memory apache module code that was written in c.
I found some codes, but none of them is working properly. I'm using ubuntu
10.10 as a development environment. Do you have any basic codes like shared
memory counter or etc.
If you can send me a working example, i'll be appreciated because i'm very
very confused and stuck about shared memory concepts. I just need a basic
example code snippet

thanks

Oğuzhan TOPGÜL

Re: basic example shared memory code

Posted by Oğuzhan TOPGÜL <og...@gmail.com>.
When i delete exit(1), nothing has changed but when i commented out all the
mutexes it works, counter is working well. That's great. :)
that means shared memory is working well.

in terms of mutexes
i need to create mutex in post config
in handler
1. lock mutex
2. process global variable
3. unlcok mutex

If i'm right what is the problem with that code, do you have any ideas or
advices about these segmentation faults.

Oğuzhan TOPGÜL


On Wed, Nov 23, 2011 at 12:39 AM, Sorin Manolache <so...@gmail.com> wrote:

> On Tue, Nov 22, 2011 at 21:25, Oğuzhan TOPGÜL <og...@gmail.com>
> wrote:
> > hey guys,
> > i'm in terrible with these shared memory.
> > I tried to write a basic module by looking at the examples that basic
> module
> > just holds a counter and prints it to the client.
> > when i compile the code attached, i got no error messages. But in apache
> > error.log file i got
> > lots of
> > [notice] child pid 32653 exit signal Segmentation fault (11)
> > and my module does not working.
> > if you have time to look at my code and send me your advices i'll be
> > appreciated. Because i'm getting crazy about these shared memory
> concepts.
> > I just want to define a global variable and process it in each request
> from
> > different sources.
> > Regards,
> > Oğuzhan TOPGÜL
>
> First remove the exit(1) from child_init. Otherwise apache does not
> succeed in creating any children.
>
> If this does not solve your problem, comment all lines dealing with
> the mutex and retry. I'm not saying that you don't need mutexes but
> commenting them out would at least restrict the area where the
> segfaults happen.
>
> S
>
> >
> >
> > On Tue, Nov 22, 2011 at 9:14 PM, Oğuzhan TOPGÜL <oguzhantopgul@gmail.com
> >
> > wrote:
> >>
> >> Thank you guys so much.
> >> What i want to do with shared memory is to hold the requester IPs and a
> >> counter that holds how many times an IP made request. I'm planning to
> hold
> >> them in a binary tree.
> >> I thought holding these IPs and counters in a file is slower than
> holding
> >> them in a shared memory because of the file I/O loss. And using binary
> tree
> >> as a data structure is going to make my search process faster and
> easier.
> >> Do you have any suggestions about shared memory-file usage or data
> >> structure usage.
> >> Regards
> >> Oğuzhan TOPGÜL
> >>
> >>
> >> On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew <ni...@apache.org> wrote:
> >>>
> >>> On Tue, 22 Nov 2011 09:41:02 -0500
> >>> "Pranesh Vadhirajan" <va...@teralogics.com> wrote:
> >>>
> >>> > Nick, can you suggest some of these higher-level abstractions,
> please?
> >>> >  I have been trying to make a module of mine work with a POSIX
> shared memory
> >>> > implementation, but I'm going nowhere with that.  Are you referring
> to the
> >>> > apache shared memory implementation (apr_shm_...) or something else?
>  Either
> >>> > way, if you could suggest what I should look into, it would be
> greatly
> >>> > appreciated.
> >>>
> >>> apr_shm is the old way of doing it.
> >>>
> >>> Today I'd recommend looking at mod_slotmem, and the socache modules.
> >>> I used the latter for mod_authn_socache, which is a simple example.
> >>>
> >>> --
> >>> Nick Kew
> >>
> >
> >
>

Re: basic example shared memory code

Posted by Sorin Manolache <so...@gmail.com>.
On Tue, Nov 22, 2011 at 21:25, Oğuzhan TOPGÜL <og...@gmail.com> wrote:
> hey guys,
> i'm in terrible with these shared memory.
> I tried to write a basic module by looking at the examples that basic module
> just holds a counter and prints it to the client.
> when i compile the code attached, i got no error messages. But in apache
> error.log file i got
> lots of
> [notice] child pid 32653 exit signal Segmentation fault (11)
> and my module does not working.
> if you have time to look at my code and send me your advices i'll be
> appreciated. Because i'm getting crazy about these shared memory concepts.
> I just want to define a global variable and process it in each request from
> different sources.
> Regards,
> Oğuzhan TOPGÜL

First remove the exit(1) from child_init. Otherwise apache does not
succeed in creating any children.

If this does not solve your problem, comment all lines dealing with
the mutex and retry. I'm not saying that you don't need mutexes but
commenting them out would at least restrict the area where the
segfaults happen.

S

>
>
> On Tue, Nov 22, 2011 at 9:14 PM, Oğuzhan TOPGÜL <og...@gmail.com>
> wrote:
>>
>> Thank you guys so much.
>> What i want to do with shared memory is to hold the requester IPs and a
>> counter that holds how many times an IP made request. I'm planning to hold
>> them in a binary tree.
>> I thought holding these IPs and counters in a file is slower than holding
>> them in a shared memory because of the file I/O loss. And using binary tree
>> as a data structure is going to make my search process faster and easier.
>> Do you have any suggestions about shared memory-file usage or data
>> structure usage.
>> Regards
>> Oğuzhan TOPGÜL
>>
>>
>> On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew <ni...@apache.org> wrote:
>>>
>>> On Tue, 22 Nov 2011 09:41:02 -0500
>>> "Pranesh Vadhirajan" <va...@teralogics.com> wrote:
>>>
>>> > Nick, can you suggest some of these higher-level abstractions, please?
>>> >  I have been trying to make a module of mine work with a POSIX shared memory
>>> > implementation, but I'm going nowhere with that.  Are you referring to the
>>> > apache shared memory implementation (apr_shm_...) or something else?  Either
>>> > way, if you could suggest what I should look into, it would be greatly
>>> > appreciated.
>>>
>>> apr_shm is the old way of doing it.
>>>
>>> Today I'd recommend looking at mod_slotmem, and the socache modules.
>>> I used the latter for mod_authn_socache, which is a simple example.
>>>
>>> --
>>> Nick Kew
>>
>
>

Re: basic example shared memory code

Posted by Oğuzhan TOPGÜL <og...@gmail.com>.
hey guys,
i'm in terrible with these shared memory.
I tried to write a basic module by looking at the examples that basic
module just holds a counter and prints it to the client.
when i compile the code attached, i got no error messages. But in apache
error.log file i got
lots of
[notice] child pid 32653 exit signal Segmentation fault (11)
and my module does not working.
if you have time to look at my code and send me your advices i'll be
appreciated. Because i'm getting crazy about these shared memory concepts.
I just want to define a global variable and process it in each request from
different sources.

Regards,
Oğuzhan TOPGÜL


On Tue, Nov 22, 2011 at 9:14 PM, Oğuzhan TOPGÜL <og...@gmail.com>wrote:

> Thank you guys so much.
> What i want to do with shared memory is to hold the requester IPs and a
> counter that holds how many times an IP made request. I'm planning to hold
> them in a binary tree.
> I thought holding these IPs and counters in a file is slower than holding
> them in a shared memory because of the file I/O loss. And using binary tree
> as a data structure is going to make my search process faster and easier.
> Do you have any suggestions about shared memory-file usage or data
> structure usage.
>
> Regards
> Oğuzhan TOPGÜL
>
>
>
> On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew <ni...@apache.org> wrote:
>
>> On Tue, 22 Nov 2011 09:41:02 -0500
>> "Pranesh Vadhirajan" <va...@teralogics.com> wrote:
>>
>> > Nick, can you suggest some of these higher-level abstractions, please?
>>  I have been trying to make a module of mine work with a POSIX shared
>> memory implementation, but I'm going nowhere with that.  Are you referring
>> to the apache shared memory implementation (apr_shm_...) or something else?
>>  Either way, if you could suggest what I should look into, it would be
>> greatly appreciated.
>>
>> apr_shm is the old way of doing it.
>>
>> Today I'd recommend looking at mod_slotmem, and the socache modules.
>> I used the latter for mod_authn_socache, which is a simple example.
>>
>> --
>> Nick Kew
>>
>
>

Re: basic example shared memory code

Posted by Oğuzhan TOPGÜL <og...@gmail.com>.
Thank you guys so much.
What i want to do with shared memory is to hold the requester IPs and a
counter that holds how many times an IP made request. I'm planning to hold
them in a binary tree.
I thought holding these IPs and counters in a file is slower than holding
them in a shared memory because of the file I/O loss. And using binary tree
as a data structure is going to make my search process faster and easier.
Do you have any suggestions about shared memory-file usage or data
structure usage.

Regards
Oğuzhan TOPGÜL


On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew <ni...@apache.org> wrote:

> On Tue, 22 Nov 2011 09:41:02 -0500
> "Pranesh Vadhirajan" <va...@teralogics.com> wrote:
>
> > Nick, can you suggest some of these higher-level abstractions, please?
>  I have been trying to make a module of mine work with a POSIX shared
> memory implementation, but I'm going nowhere with that.  Are you referring
> to the apache shared memory implementation (apr_shm_...) or something else?
>  Either way, if you could suggest what I should look into, it would be
> greatly appreciated.
>
> apr_shm is the old way of doing it.
>
> Today I'd recommend looking at mod_slotmem, and the socache modules.
> I used the latter for mod_authn_socache, which is a simple example.
>
> --
> Nick Kew
>

Re: basic example shared memory code

Posted by Nick Kew <ni...@apache.org>.
On Tue, 22 Nov 2011 09:41:02 -0500
"Pranesh Vadhirajan" <va...@teralogics.com> wrote:

> Nick, can you suggest some of these higher-level abstractions, please?  I have been trying to make a module of mine work with a POSIX shared memory implementation, but I'm going nowhere with that.  Are you referring to the apache shared memory implementation (apr_shm_...) or something else?  Either way, if you could suggest what I should look into, it would be greatly appreciated.

apr_shm is the old way of doing it.

Today I'd recommend looking at mod_slotmem, and the socache modules.
I used the latter for mod_authn_socache, which is a simple example.

-- 
Nick Kew

RE: basic example shared memory code

Posted by Pranesh Vadhirajan <va...@teralogics.com>.
Nick, can you suggest some of these higher-level abstractions, please?  I have been trying to make a module of mine work with a POSIX shared memory implementation, but I'm going nowhere with that.  Are you referring to the apache shared memory implementation (apr_shm_...) or something else?  Either way, if you could suggest what I should look into, it would be greatly appreciated.

Thanks,
Pranesh

-----Original Message-----
From: Nick Kew [mailto:niq@apache.org] 
Sent: Tuesday, November 22, 2011 7:44 AM
To: modules-dev@httpd.apache.org
Subject: Re: basic example shared memory code


On 22 Nov 2011, at 09:26, Oğuzhan TOPGÜL wrote:

> Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
> example shared memory apache module code that was written in c.

If you're planning to write a module, bear in mind that apache now provides
easy-to-use higher-level abstractions for shared memory.  Older modules
had to work much harder to do the same thing, so looking at them may not
be your best approach.

-- 
Nick Kew

Re: basic example shared memory code

Posted by Nick Kew <ni...@apache.org>.
On 22 Nov 2011, at 09:26, Oğuzhan TOPGÜL wrote:

> Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
> example shared memory apache module code that was written in c.

If you're planning to write a module, bear in mind that apache now provides
easy-to-use higher-level abstractions for shared memory.  Older modules
had to work much harder to do the same thing, so looking at them may not
be your best approach.

-- 
Nick Kew

Re: basic example shared memory code

Posted by MATSUMOTO Ryosuke <ma...@gmail.com>.
mod_vlimit https://modules.apache.org/search.php?id=2570

This module count a number of simultaneous connections on shared memory.

2011/11/22 michaelr <my...@freenet.de>:
> On Tue, 2011-11-22 at 11:26 +0200, Oğuzhan TOPGÜL wrote:
>> Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
>> example shared memory apache module code that was written in c.
>> I found some codes, but none of them is working properly. I'm using ubuntu
>> 10.10 as a development environment. Do you have any basic codes like shared
>> memory counter or etc.
>> If you can send me a working example, i'll be appreciated because i'm very
>> very confused and stuck about shared memory concepts. I just need a basic
>> example code snippet
>>
>
> The example module from: http://www.codemass.com/mod_shm_counter/
> helped me a lot understanding the basic concepts of the apr shared
> memory functions.
>
>
>
>



-- 
MATSUMOTO Ryosuke < matsu1229 at gmail.com >
http://blog.matsumoto-r.jp/

RE: basic example shared memory code

Posted by Pranesh Vadhirajan <va...@teralogics.com>.
Hi 
     I compiled the code from the link you provided, but I received the following error when I restarted httpd: 
	API module structure `shm_counter_module' in file /usr/lib/httpd/modules/shm_counter.so is garbled - perhaps this is not an Apache module DSO?

I am not sure why I receive this error.  I'm running Apache 2.2.3 on a 64 bit Red Linux system.  Any ideas on how to solve this issue?

Pranesh

-----Original Message-----
From: michaelr [mailto:mypop@freenet.de] 
Sent: Tuesday, November 22, 2011 4:37 AM
To: modules-dev@httpd.apache.org
Subject: Re: basic example shared memory code

On Tue, 2011-11-22 at 11:26 +0200, Oğuzhan TOPGÜL wrote:
> Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
> example shared memory apache module code that was written in c.
> I found some codes, but none of them is working properly. I'm using ubuntu
> 10.10 as a development environment. Do you have any basic codes like shared
> memory counter or etc.
> If you can send me a working example, i'll be appreciated because i'm very
> very confused and stuck about shared memory concepts. I just need a basic
> example code snippet
> 

The example module from: http://www.codemass.com/mod_shm_counter/
helped me a lot understanding the basic concepts of the apr shared
memory functions.




Re: basic example shared memory code

Posted by michaelr <my...@freenet.de>.
On Tue, 2011-11-22 at 11:26 +0200, Oğuzhan TOPGÜL wrote:
> Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
> example shared memory apache module code that was written in c.
> I found some codes, but none of them is working properly. I'm using ubuntu
> 10.10 as a development environment. Do you have any basic codes like shared
> memory counter or etc.
> If you can send me a working example, i'll be appreciated because i'm very
> very confused and stuck about shared memory concepts. I just need a basic
> example code snippet
> 

The example module from: http://www.codemass.com/mod_shm_counter/
helped me a lot understanding the basic concepts of the apr shared
memory functions.