Share perl variables between apache process
Share perl variables between apache process
am 23.09.2008 21:11:03 von badman
Hello, i'm studying mod_perl and was wondering if it could be possible to
share data among child process.
I'll explain me better.
i create a variable in startup.pl like in ...
http://perl.apache.org/docs/2.0/user/coding/coding.html#Meth od_Handlers Here
use Bird::Eagle;
$Bird::Global::object = Bird::Eagle->new();
Now i have many instance of this object as any interpreter are in use, am i
right?
So everytime i update some attributes of $Bird::Global::object it change
only in some process.
I was asking if there is a way that i could get a really shared variable
among all the process, it could be helpful to investigate threads's module?
Thanks
--
View this message in context: http://www.nabble.com/Share-perl-variables-between-apache-pr ocess-tp19634770p19634770.html
Sent from the mod_perl - General mailing list archive at Nabble.com.
Re: Share perl variables between apache process
am 23.09.2008 22:06:07 von Ryan Gies
On Tue, 23 Sep 2008 12:11:03 -0700 (PDT)
badman wrote:
> I was asking if there is a way that i could get a really shared
> variable among all the process,
I had no problems using IPC::Sharable with mp2 and it may be what
you're looking for. I do not use this in production as the data shared
does not persist user permissions, e.g., a shared object create by root
can be accessed by any process running under any user permitting they
have the 4-character key.
> it could be helpful to investigate threads's module?
Yes, understand your Apache MPM, how Perl is compiled, and the
implications of using shared memory (/shm) in general. I wouldn't take
this lightly in the context of a production web server.
Re: Share perl variables between apache process
am 23.09.2008 22:15:26 von mpeters
badman wrote:
> i create a variable in startup.pl like in ...
> http://perl.apache.org/docs/2.0/user/coding/coding.html#Meth od_Handlers Here
> use Bird::Eagle;
> $Bird::Global::object = Bird::Eagle->new();
> Now i have many instance of this object as any interpreter are in use, am i
> right?
Yes, each Apache process has it's own Perl interpreter, so nothing is shared.
> So everytime i update some attributes of $Bird::Global::object it change
> only in some process.
Yes.
> I was asking if there is a way that i could get a really shared variable
> among all the process, it could be helpful to investigate threads's module?
Can I ask why? Most people these days are moving away from shared variables in lots of programming
contexts (not just Perl or mod_perl). It might seem easier at first, but it actually makes your
programs work harder (managing resource locks, semaphores, etc). Using a shared variable means your
application will be stuck to just working on a single machine (bye-bye scalability).
Even Google's Chrome (it's new browser) uses a multi-process architecture for some of these same
reasons (utilize multiple cores, isolation of concurrent tasks).
--
Michael Peters
Plus Three, LP
Re: Share perl variables between apache process
am 24.09.2008 09:08:50 von badman
Tnx for the replies
For Michael, yes i know what it mean to have global variables (semaphores,
....) i was investigating this option because when i do call ...->new(); it
reads a file to initiate its attribute.
I would like to improve the performance not reading always the file
For Ryan, i already see IPC::Shareable before using it i was investigating
some other option, but i think i'l use it :)
--
View this message in context: http://www.nabble.com/Share-perl-variables-between-apache-pr ocess-tp19634770p19643172.html
Sent from the mod_perl - General mailing list archive at Nabble.com.
Re: Share perl variables between apache process
am 24.09.2008 21:17:15 von Perrin Harkins
On Wed, Sep 24, 2008 at 3:08 AM, badman wrote:
> For Michael, yes i know what it mean to have global variables (semaphores,
> ...) i was investigating this option because when i do call ...->new(); it
> reads a file to initiate its attribute.
> I would like to improve the performance not reading always the file
If the file doesn't change, read it into a global in the parent
process before forking. Then you'll have it for use in the children.
> For Ryan, i already see IPC::Shareable before using it i was investigating
> some other option, but i think i'l use it :)
Be careful, IPC::Shareable is pretty slow, especially for large chunks
of data. In most cases, an RDBMS or a dbm file ends up being faster.
- Perrin
Re: Share perl variables between apache process
am 24.09.2008 23:32:58 von jonathan vanasco
On Sep 24, 2008, at 3:17 PM, Perrin Harkins wrote:
> On Wed, Sep 24, 2008 at 3:08 AM, badman wrote:
>> For Michael, yes i know what it mean to have global variables
>> (semaphores,
>> ...) i was investigating this option because when i do call ...-
>> >new(); it
>> reads a file to initiate its attribute.
>> I would like to improve the performance not reading always the file
>
> If the file doesn't change, read it into a global in the parent
> process before forking. Then you'll have it for use in the children.
>
>> For Ryan, i already see IPC::Shareable before using it i was
>> investigating
>> some other option, but i think i'l use it :)
>
> Be careful, IPC::Shareable is pretty slow, especially for large chunks
> of data. In most cases, an RDBMS or a dbm file ends up being faster.
also memcached can work well here
// Jonathan Vanasco
w. http://findmeon.com/user/jvanasco
e. jonathan@findmeon.com
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
| Founder/CEO
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Privacy Minded Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -