Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Share perl variables between apache process

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


rafspiny at gmail

Sep 23, 2008, 12:11 PM

Post #1 of 6 (695 views)
Permalink
Share perl variables between apache process

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#Method_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-process-tp19634770p19634770.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


ryan at livesite

Sep 23, 2008, 1:06 PM

Post #2 of 6 (649 views)
Permalink
Re: Share perl variables between apache process [In reply to]

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.


mpeters at plusthree

Sep 23, 2008, 1:15 PM

Post #3 of 6 (644 views)
Permalink
Re: Share perl variables between apache process [In reply to]

badman wrote:

> i create a variable in startup.pl like in ...
> http://perl.apache.org/docs/2.0/user/coding/coding.html#Method_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


rafspiny at gmail

Sep 24, 2008, 12:08 AM

Post #4 of 6 (639 views)
Permalink
Re: Share perl variables between apache process [In reply to]

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-process-tp19634770p19643172.html
Sent from the mod_perl - General mailing list archive at Nabble.com.


perrin at elem

Sep 24, 2008, 12:17 PM

Post #5 of 6 (618 views)
Permalink
Re: Share perl variables between apache process [In reply to]

On Wed, Sep 24, 2008 at 3:08 AM, badman <rafspiny [at] gmail> 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


jonathan at 2xlp

Sep 24, 2008, 2:32 PM

Post #6 of 6 (618 views)
Permalink
Re: Share perl variables between apache process [In reply to]

On Sep 24, 2008, at 3:17 PM, Perrin Harkins wrote:

> On Wed, Sep 24, 2008 at 3:08 AM, badman <rafspiny [at] gmail> 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 [at] findmeon

| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
| Founder/CEO
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
| FindMeOn.com - The cure for Multiple Web Personality Disorder
| Privacy Minded Web Identity Management and 3D Social Networking
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.