Share perl variables between apache process - modperl

This is a discussion on Share perl variables between apache process - modperl ; 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...ethod_Handlers Here use Bird::Eagle; $Bird::Global: bject = Bird::Eagle->new(); Now ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Share perl variables between apache process

  1. 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...ethod_Handlers Here
    use Bird::Eagle;
    $Bird::Global:bject = 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:bject 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-var...p19634770.html
    Sent from the mod_perl - General mailing list archive at Nabble.com.


  2. Re: Share perl variables between apache process

    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.


  3. Re: Share perl variables between apache process

    badman wrote:

    > i create a variable in startup.pl like in ...
    > http://perl.apache.org/docs/2.0/user...ethod_Handlers Here
    > use Bird::Eagle;
    > $Bird::Global:bject = 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:bject 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


  4. Re: Share perl variables between apache process


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


  5. Re: Share perl variables between apache process

    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


  6. Re: Share perl variables between apache process


    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
    | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - - - - - - - - - -


+ Reply to Thread