You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Felipe de Jesús Molina Bravo <fj...@gmail.com> on 2008/04/03 17:32:16 UTC

share objects

hi

I have  installed static mp2 with apache 2.0.63 (forker).  I am using perl
bind (Sleepycat::DBXML) from dbxml; then I create an object (reference to
Sleepycat::DBXML) in startup.pl because i want to share it. After some test
(stress it) for my application I saw some error in error.log; the problem is
that reference to object created in startup.pl was lost

then the question is ... is possible to share objects?


I know I can share data between processes, but what I also shared objects?



thanks in advance

Re: share objects

Posted by Felipe de Jesús Molina Bravo <fj...@gmail.com>.
2008/4/3, Perrin Harkins <pe...@elem.com>:
>
> On Thu, Apr 3, 2008 at 1:33 PM, Felipe de Jesús Molina Bravo
> <fj...@gmail.com> wrote:
> > > It depends on what you mean by share.  You can create a simple perl
> > > object in startup.pl and access it from all processes later, but if
> > > you change it in one process, the change will not be seen in the
> > > others.  With objects that contain open sockets, file handles, or XS
> > > structures, you usually can't share them at all.
> >
> > Is when they can be shared?  and if my file handle is open of "ro"  ....
> it
> > can share between process?
>
>
> It can be done, but it's tricky.  When you try to use one file handle
> from multiple process it gets confused about the location in the file.
>   If you really need to do it, read about shared file handles in
> Programming Perl or your favorite Unix reference.
>
>
> - Perrin
>

ok ...thanks a lot


regards
felipe

Re: share objects

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, Apr 3, 2008 at 1:33 PM, Felipe de Jesús Molina Bravo
<fj...@gmail.com> wrote:
> > It depends on what you mean by share.  You can create a simple perl
> > object in startup.pl and access it from all processes later, but if
> > you change it in one process, the change will not be seen in the
> > others.  With objects that contain open sockets, file handles, or XS
> > structures, you usually can't share them at all.
>
> Is when they can be shared?  and if my file handle is open of "ro"  .... it
> can share between process?

It can be done, but it's tricky.  When you try to use one file handle
from multiple process it gets confused about the location in the file.
 If you really need to do it, read about shared file handles in
Programming Perl or your favorite Unix reference.

- Perrin

Re: share objects

Posted by Felipe de Jesús Molina Bravo <fj...@gmail.com>.
2008/4/3, Perrin Harkins <pe...@elem.com>:
>
> On Thu, Apr 3, 2008 at 11:32 AM, Felipe de Jesús Molina Bravo
> <fj...@gmail.com> wrote:
>
> > I know I can share data between processes, but what I also shared
> objects?
>
>
> It depends on what you mean by share.  You can create a simple perl
> object in startup.pl and access it from all processes later, but if
> you change it in one process, the change will not be seen in the
> others.  With objects that contain open sockets, file handles, or XS
> structures, you usually can't share them at all.


Is when they can be shared?  and if my file handle is open of "ro"  .... it
can share between process?


This is why you
> can't open a DBI connection in startup and use it from your child
> processes.
>
> I don't know Sleepycat::DBXML, but it sounds like something that would
> use file handles.  Try creating your object in a PerlInitHandler
> instead, which runs in the child process when it is first created.

- Perrin
>

Thanks ...
best regards

felipe

Re: share objects

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, Apr 3, 2008 at 11:32 AM, Felipe de Jesús Molina Bravo
<fj...@gmail.com> wrote:
> I know I can share data between processes, but what I also shared objects?

It depends on what you mean by share.  You can create a simple perl
object in startup.pl and access it from all processes later, but if
you change it in one process, the change will not be seen in the
others.  With objects that contain open sockets, file handles, or XS
structures, you usually can't share them at all.  This is why you
can't open a DBI connection in startup and use it from your child
processes.

I don't know Sleepycat::DBXML, but it sounds like something that would
use file handles.  Try creating your object in a PerlInitHandler
instead, which runs in the child process when it is first created.

- Perrin

Re: share objects

Posted by Felipe de Jesús Molina Bravo <fj...@gmail.com>.
2008/4/3, Jeff Pang <pa...@earthlink.net>:
>
> On Thu, Apr 3, 2008 at 11:32 PM, Felipe de Jesús Molina Bravo
> <fj...@gmail.com> wrote:
> > hi
> >
> > I have  installed static mp2 with apache 2.0.63 (forker).  I am using
> perl
> > bind (Sleepycat::DBXML) from dbxml; then I create an object (reference
> to
> > Sleepycat::DBXML) in startup.pl because i want to share it. After some
> test
> > (stress it) for my application I saw some error in error.log; the
> problem is
> > that reference to object created in startup.pl was lost
> >
> > then the question is ... is possible to share objects?
> >
>
>
> If your object has its own package name space, you can share it
> between multi-processes.
> But if you state this in startup.pl,
>
> my $obj = Sleepycat::DBXML->new();
>
> this $obj can't be shared among multi-processes. Because it doesn't
> have its package name space.
>
> So,you'd better write a package to encap that object, like:
>
> package MyPKG;
> use strict;
> use Sleepycat::DBXML;
>
> our $obj =  Sleepycat::DBXML->new;
> sub initobj { $obj }
>
> 1;
>
> And put 'use MyPKG' in the startup.pl.
> then in your scripts you can access this object by saying 'our $obj'
> or via the method of 'my $obj = MyPKG->initobj'.
>
> Good luck.
>

thanks a lot

My problem was solved ... The problem was that I had the buildup of the
object (new) within "sub initobj () "

regards

Re: share objects

Posted by Jeff Pang <pa...@earthlink.net>.
On Thu, Apr 3, 2008 at 11:32 PM, Felipe de Jesús Molina Bravo
<fj...@gmail.com> wrote:
> hi
>
> I have  installed static mp2 with apache 2.0.63 (forker).  I am using perl
> bind (Sleepycat::DBXML) from dbxml; then I create an object (reference to
> Sleepycat::DBXML) in startup.pl because i want to share it. After some test
> (stress it) for my application I saw some error in error.log; the problem is
> that reference to object created in startup.pl was lost
>
> then the question is ... is possible to share objects?
>

If your object has its own package name space, you can share it
between multi-processes.
But if you state this in startup.pl,

my $obj = Sleepycat::DBXML->new();

this $obj can't be shared among multi-processes. Because it doesn't
have its package name space.

So,you'd better write a package to encap that object, like:

package MyPKG;
use strict;
use Sleepycat::DBXML;

our $obj =  Sleepycat::DBXML->new;
sub initobj { $obj }

1;

And put 'use MyPKG' in the startup.pl.
then in your scripts you can access this object by saying 'our $obj'
or via the method of 'my $obj = MyPKG->initobj'.

Good luck.