You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by mo...@normalperson.e4ward.com on 2010/02/03 06:45:06 UTC

global variable

Hello,

Is there a method to setup a global variable for all modperl child processes?
Also this variable will be updated sometime, when it get updated, all
processes will know it.

Thanks.

Re: global variable

Posted by cr...@animalhead.com.
Just thought to add:

One of the most interesting uses of IPC::MMA is to create a shared
memory in a PerlPostConfigHandler, and then use it to tie scalars or
arrays or hashes in other modules into the shared memory.

In write-seldom, read-mostly applications like the cache hash in
Image::Size, this can be done without any change to the other module.

cmac

On Feb 3, 2010, at 9:20 AM, Boysenberry Payne wrote:

> Looks like a great module.
> It says early on in the docs that it doesn't use references; does  
> that mean we need to dereference in order to store that values?
>
> Thanks,
> Boysenberry Payne
>
> On Feb 3, 2010, at 10:17 AM, mackenna@animalhead.com wrote:
>
>> I rewrote IPC::MMA from an earlier CPAN module so that I could
>> use shared memory among Apache children.  You can read about it at
>> http://search.cpan.org/~mackenna/IPC-MMA-0.6/MMA.pod
>>
>> On Feb 2, 2010, at 9:45 PM, moli@normalperson.e4ward.com wrote:
>>
>>> Hello,
>>>
>>> Is there a method to setup a global variable for all modperl  
>>> child processes?
>>> Also this variable will be updated sometime, when it get updated,  
>>> all
>>> processes will know it.
>>>
>>> Thanks.
>>
>


Re: global variable

Posted by Boysenberry Payne <bo...@habitatlife.com>.
Looks like a great module.
It says early on in the docs that it doesn't use references; does that mean we need to dereference in order to store that values?

Thanks,
Boysenberry Payne

On Feb 3, 2010, at 10:17 AM, mackenna@animalhead.com wrote:

> I rewrote IPC::MMA from an earlier CPAN module so that I could
> use shared memory among Apache children.  You can read about it at
> http://search.cpan.org/~mackenna/IPC-MMA-0.6/MMA.pod
> 
> On Feb 2, 2010, at 9:45 PM, moli@normalperson.e4ward.com wrote:
> 
>> Hello,
>> 
>> Is there a method to setup a global variable for all modperl child processes?
>> Also this variable will be updated sometime, when it get updated, all
>> processes will know it.
>> 
>> Thanks.
> 


RE: global variable

Posted by Morten Bjørnsvik <mo...@experian-da.no>.
Hi Craig

Thanks for the info. You should add this to the perldoc, as selling points
making it more attractive in the IPC::* modules jungle.

IPC::Cache is limited by Storable. It is Storable that do
not allow typeglobs.

There is no problem storing whatever data as long as it resides in shmem and you only
issue references to it. We do it manually, but I've not found any cpan modules that do this.
Or maybe many may work, but they do not have it documented in the perldoc.

We will try your module and play around with it, Thanks again

--
MortenB


-----Original Message-----
From: craig@animalhead.com [mailto:craig@animalhead.com] 
Sent: 4. februar 2010 19:06
To: Morten Bjørnsvik
Cc: modperl@perl.apache.org list
Subject: Re: global variable

Hi,

IPC::MMA and its underlying MM library are written entirely in C.
I originally got into this business when I read some user reviews
that said that the predecessor module IPC::MM was the fastest
module of its kind that they could find.

IPC::MMA cleaned up several things in IPC::MM, including
generalized keys as in Perl hashes. (IPC::MM only allowed C
strings as keys.)  IPC:MMA is probably faster than IPC::MM.
But I've never done any benchmarks to back up this claim, nor
against other modules.

The direct-call interface is inevitably slightly faster than the
tied interface.

IPC::MMA only allows sharing among parent and child processes,
including between children.  The general idea is to create the
shared memory, and most or all of the data structures, in the
parent process before it forks (e.g., in an Apache PostConfigHandler).

If the relationship with the backend daemon isn't parent:child or
child:child, you can't use IPC::MMA to share data with the backend
daemon.

I have to plead ignorance of the fine points of typeglobs.  I've
used the * notation when an example told me to, without thinking
much about it.

Having read all the 'typeglob' references in Programming Perl and
those in the perl internal docs, they sound like data structures
containing addresses of things, i.e., references to things.
Except for addresses in shared segments, one process can only
access the content of its own memory via addresses, not the
memory of other processes.

In C, filehandles are just integers, which are eminently sharable.

Best Regards,
cmac


On Feb 4, 2010, at 12:33 AM, Morten Bjørnsvik wrote:

> Hi
>
> We have been using IPC::Cache for this for years, but it does not  
> store typeglobs (filehandlers, sockets etc)
> Forcing us to use local unix sockets to communicate with the  
> backend daemon. This mean we always have to
> have a daemon node on every web-server instead of just a single node.
>
> I do not see IPC::MMA store typeglobs either, is it faster?
>
> We have our own workaround using IPC::SysV and IPC::Msg, they are  
> extremely fast compared to IPC::Cache, but
> has awkward hash key management I like to drop if we find something  
> faster.
>
>
> Thanks
>
> --
> Morten Bjoernsvik,  Experian Decision Analytics, Oslo, Norway.
>
> -----Original Message-----
> From: mackenna@animalhead.com [mailto:mackenna@animalhead.com]
> Sent: 3. februar 2010 18:18
> To: moli@normalperson.e4ward.com
> Cc: modperl@perl.apache.org
> Subject: Re: global variable
>
> I rewrote IPC::MMA from an earlier CPAN module so that I could
> use shared memory among Apache children.  You can read about it at
> http://search.cpan.org/~mackenna/IPC-MMA-0.6/MMA.pod
>
> On Feb 2, 2010, at 9:45 PM, moli@normalperson.e4ward.com wrote:
>
>> Hello,
>>
>> Is there a method to setup a global variable for all modperl child
>> processes?
>> Also this variable will be updated sometime, when it get updated, all
>> processes will know it.
>>
>> Thanks.
>


Re: global variable

Posted by cr...@animalhead.com.
Hi,

IPC::MMA and its underlying MM library are written entirely in C.
I originally got into this business when I read some user reviews
that said that the predecessor module IPC::MM was the fastest
module of its kind that they could find.

IPC::MMA cleaned up several things in IPC::MM, including
generalized keys as in Perl hashes. (IPC::MM only allowed C
strings as keys.)  IPC:MMA is probably faster than IPC::MM.
But I've never done any benchmarks to back up this claim, nor
against other modules.

The direct-call interface is inevitably slightly faster than the
tied interface.

IPC::MMA only allows sharing among parent and child processes,
including between children.  The general idea is to create the
shared memory, and most or all of the data structures, in the
parent process before it forks (e.g., in an Apache PostConfigHandler).

If the relationship with the backend daemon isn't parent:child or
child:child, you can't use IPC::MMA to share data with the backend
daemon.

I have to plead ignorance of the fine points of typeglobs.  I've
used the * notation when an example told me to, without thinking
much about it.

Having read all the 'typeglob' references in Programming Perl and
those in the perl internal docs, they sound like data structures
containing addresses of things, i.e., references to things.
Except for addresses in shared segments, one process can only
access the content of its own memory via addresses, not the
memory of other processes.

In C, filehandles are just integers, which are eminently sharable.

Best Regards,
cmac


On Feb 4, 2010, at 12:33 AM, Morten Bjørnsvik wrote:

> Hi
>
> We have been using IPC::Cache for this for years, but it does not  
> store typeglobs (filehandlers, sockets etc)
> Forcing us to use local unix sockets to communicate with the  
> backend daemon. This mean we always have to
> have a daemon node on every web-server instead of just a single node.
>
> I do not see IPC::MMA store typeglobs either, is it faster?
>
> We have our own workaround using IPC::SysV and IPC::Msg, they are  
> extremely fast compared to IPC::Cache, but
> has awkward hash key management I like to drop if we find something  
> faster.
>
>
> Thanks
>
> --
> Morten Bjoernsvik,  Experian Decision Analytics, Oslo, Norway.
>
> -----Original Message-----
> From: mackenna@animalhead.com [mailto:mackenna@animalhead.com]
> Sent: 3. februar 2010 18:18
> To: moli@normalperson.e4ward.com
> Cc: modperl@perl.apache.org
> Subject: Re: global variable
>
> I rewrote IPC::MMA from an earlier CPAN module so that I could
> use shared memory among Apache children.  You can read about it at
> http://search.cpan.org/~mackenna/IPC-MMA-0.6/MMA.pod
>
> On Feb 2, 2010, at 9:45 PM, moli@normalperson.e4ward.com wrote:
>
>> Hello,
>>
>> Is there a method to setup a global variable for all modperl child
>> processes?
>> Also this variable will be updated sometime, when it get updated, all
>> processes will know it.
>>
>> Thanks.
>


RE: global variable

Posted by Morten Bjørnsvik <mo...@experian-da.no>.
Hi

We have been using IPC::Cache for this for years, but it does not store typeglobs (filehandlers, sockets etc)
Forcing us to use local unix sockets to communicate with the backend daemon. This mean we always have to
have a daemon node on every web-server instead of just a single node. 

I do not see IPC::MMA store typeglobs either, is it faster?

We have our own workaround using IPC::SysV and IPC::Msg, they are extremely fast compared to IPC::Cache, but
has awkward hash key management I like to drop if we find something faster.


Thanks

--
Morten Bjoernsvik,  Experian Decision Analytics, Oslo, Norway.

-----Original Message-----
From: mackenna@animalhead.com [mailto:mackenna@animalhead.com] 
Sent: 3. februar 2010 18:18
To: moli@normalperson.e4ward.com
Cc: modperl@perl.apache.org
Subject: Re: global variable

I rewrote IPC::MMA from an earlier CPAN module so that I could
use shared memory among Apache children.  You can read about it at
http://search.cpan.org/~mackenna/IPC-MMA-0.6/MMA.pod

On Feb 2, 2010, at 9:45 PM, moli@normalperson.e4ward.com wrote:

> Hello,
>
> Is there a method to setup a global variable for all modperl child  
> processes?
> Also this variable will be updated sometime, when it get updated, all
> processes will know it.
>
> Thanks.


Re: global variable

Posted by ma...@animalhead.com.
I rewrote IPC::MMA from an earlier CPAN module so that I could
use shared memory among Apache children.  You can read about it at
http://search.cpan.org/~mackenna/IPC-MMA-0.6/MMA.pod

On Feb 2, 2010, at 9:45 PM, moli@normalperson.e4ward.com wrote:

> Hello,
>
> Is there a method to setup a global variable for all modperl child  
> processes?
> Also this variable will be updated sometime, when it get updated, all
> processes will know it.
>
> Thanks.


Re: global variable

Posted by Fayland Lam <fa...@gmail.com>.
why not use memcached or FastMmap?

Thanks

On 2010-2-3 16:19, moli@normalperson.e4ward.com wrote:
> On Wed, Feb 3, 2010 at 4:18 PM,<mo...@normalperson.e4ward.com>  wrote:
>    
>> On Wed, Feb 3, 2010 at 3:20 PM, André Warnier<aw...@ice-sa.com>  wrote:
>>
>>      
>>> But if you give some more details about the platform, the Apache, and what
>>> you are trying to do, someone may be able to suggest an alternative.
>>>
>>>
>>>        
>> Something linke java servlet's global variable.
>>      
> sorry for the typo,  something like ...
>
>    


-- 
Fayland Lam // http://www.fayland.org/


Re: global variable

Posted by mo...@normalperson.e4ward.com.
On Wed, Feb 3, 2010 at 4:18 PM,  <mo...@normalperson.e4ward.com> wrote:
> On Wed, Feb 3, 2010 at 3:20 PM, André Warnier <aw...@ice-sa.com> wrote:
>
>> But if you give some more details about the platform, the Apache, and what
>> you are trying to do, someone may be able to suggest an alternative.
>>
>>
>
> Something linke java servlet's global variable.

sorry for the typo,  something like ...

Re: global variable

Posted by David Nicol <da...@gmail.com>.
DirDB provides a very simple persistence, sharable data structure,
using the file system.

Re: global variable

Posted by mo...@normalperson.e4ward.com.
On Wed, Feb 3, 2010 at 3:20 PM, André Warnier <aw...@ice-sa.com> wrote:

> But if you give some more details about the platform, the Apache, and what
> you are trying to do, someone may be able to suggest an alternative.
>
>

Something linke java servlet's global variable.
Maybe set it via environment variable?

Thanks.

Re: global variable

Posted by Perrin Harkins <ph...@gmail.com>.
On Wed, Feb 3, 2010 at 2:20 AM, André Warnier <aw...@ice-sa.com> wrote:
> moli@normalperson.e4ward.com wrote:
>>
>> Hello,
>>
>> Is there a method to setup a global variable for all modperl child
>> processes?
>> Also this variable will be updated sometime, when it get updated, all
>> processes will know it.
>>
> As a general answer, no.

That's right.  Apache uses multiple processes and there's no built-in
way to share perl variables between them.  If you want to share data
and don't want to use a database, look at tools like CHI on CPAN.

- Perrin

Re: global variable

Posted by André Warnier <aw...@ice-sa.com>.
moli@normalperson.e4ward.com wrote:
> Hello,
> 
> Is there a method to setup a global variable for all modperl child processes?
> Also this variable will be updated sometime, when it get updated, all
> processes will know it.
> 
As a general answer, no.
That is because each child has its own separate perl interpreter, and 
each has its own separate memory and set of variables.

That is the only answer that is valid in all cases, under all platforms 
and all variations of Apache.
But if you give some more details about the platform, the Apache, and 
what you are trying to do, someone may be able to suggest an alternative.


Re: global variable

Posted by Torsten Förtsch <to...@gmx.net>.
On Wednesday 03 February 2010 06:45:06 moli@normalperson.e4ward.com wrote:
> Is there a method to setup a global variable for all modperl child
>  processes? Also this variable will be updated sometime, when it get
>  updated, all processes will know it.
> 
File::Map mmap()s a file and makes it visible as a perl string. You can modify 
it for example by using the lvalue form of substr().

MMapDB uses File::Map and provides some kind of a hash. (I have just uploaded 
version 0.07 that handles utf8 strings correctly (me thinks so))

There is a mod_slotmem.c floating around. It provides something like apache's 
scoreboard. That means each worker gets its own piece of shared memory to 
write to while all slots can be read by anyone. I think it can be interfaced 
to be used by Perl.

Torsten