global variable

global variable

am 03.02.2010 06:45:06 von moli

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

am 03.02.2010 08:20:52 von aw

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

am 03.02.2010 09:18:37 von moli

On Wed, Feb 3, 2010 at 3:20 PM, André Warnier wrote:

> But if you give some more details about the platform, the Apache, and wha=
t
> 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

am 03.02.2010 09:19:58 von moli

On Wed, Feb 3, 2010 at 4:18 PM, wrote:
> On Wed, Feb 3, 2010 at 3:20 PM, André Warnier wrote:
>
>> But if you give some more details about the platform, the Apache, and wh=
at
>> 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

am 03.02.2010 09:27:07 von Fayland

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, wrote:
>
>> On Wed, Feb 3, 2010 at 3:20 PM, André Warnier 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

am 03.02.2010 09:53:06 von torsten.foertsch

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

Re: global variable

am 03.02.2010 15:16:23 von Perrin Harkins

On Wed, Feb 3, 2010 at 2:20 AM, Andr=E9 Warnier 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

am 03.02.2010 18:17:50 von Craig or Merikay MacKenna

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

am 03.02.2010 18:20:58 von Boysenberry Payne

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
>=20
> On Feb 2, 2010, at 9:45 PM, moli@normalperson.e4ward.com wrote:
>=20
>> Hello,
>>=20
>> 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.
>>=20
>> Thanks.
>=20

Re: global variable

am 03.02.2010 19:27:24 von Craig MacKenna

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

am 03.02.2010 19:49:13 von David Nicol

DirDB provides a very simple persistence, sharable data structure,
using the file system.

RE: global variable

am 04.02.2010 09:33:50 von morten.bjornsvik

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.=20

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]=20
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 =20
> processes?
> Also this variable will be updated sometime, when it get updated, all
> processes will know it.
>
> Thanks.

Re: global variable

am 04.02.2010 19:05:37 von Craig MacKenna

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=F8rnsvik wrote:

> Hi
>
> We have been using IPC::Cache for this for years, but it does not =20
> store typeglobs (filehandlers, sockets etc)
> Forcing us to use local unix sockets to communicate with the =20
> 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 =20
> extremely fast compared to IPC::Cache, but
> has awkward hash key management I like to drop if we find something =20=

> 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

am 05.02.2010 10:27:48 von morten.bjornsvik

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]=20
Sent: 4. februar 2010 19:06
To: Morten Bj=F8rnsvik
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=F8rnsvik wrote:

> Hi
>
> We have been using IPC::Cache for this for years, but it does not =20
> store typeglobs (filehandlers, sockets etc)
> Forcing us to use local unix sockets to communicate with the =20
> 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 =20
> extremely fast compared to IPC::Cache, but
> has awkward hash key management I like to drop if we find something =20
> 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.
>