You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by pe...@aol.co.uk on 2007/09/24 12:08:45 UTC
load large data
Hello,
I have a module,which loads large data into memory.
my $data = Mymodule->new;
this will take some ms to be finished.
So I think I can create this object at startup time,and share the $data
acrosss all apache child processes.
Is it possible?How can I do it?
thank u.
________________________________________________________________________
Check out the new free AOL Email -- 2GB of storage and industry-leading
spam and email virus protection.
Re: load large data
Posted by Manoj Bist <ma...@gmail.com>.
You can use regular package inheritance(@ISA) support in perl to
extend MyModule and created YourModule, where you can add any extra
methods/override existing methods.
On 9/25/07, pennyyh@aol.co.uk <pe...@aol.co.uk> wrote:
> Thank you.
> Sorry that module of Mymodule is a public module from CPAN.I can't
> modify it to add the init() and data() methods.
> How to do it then?thanks again.
>
> -----Original Message-----
> From: fred@redhotpenguin.com
> To: pennyyh@aol.co.uk
> CC: modperl@perl.apache.org
> Sent: Tue, 25 Sep 2007 4.52PM
> Subject: Re: load large data
>
> pennyyh@aol.co.uk wrote:
> > Thank you.
> > I have added these directives in httpd.conf,
> > > <Perl>
> > use Mymodule;
> > our $data = Mymodule->new;
> > </Perl>
> > > Then I run bin/apachectl configtest,but got the errors,
> > > Unknown type 'Mymodule' for directive data at >
> /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache2/PerlSectio
>
> > ns.pm line 192.\n
> > > Please help.Thanks.
>
> As with all Perl code, there is more than one way to do it. Another way
> to accomplish what you are trying to do is through the use of
> startup.pl, which is run during apache startup. (I don't know why that
> error above is occurring so I'm posting this as an alternate approach).
>
> # httpd.conf
> PerlPostConfigRequire /home/pennyyh/perl/lib/startup.pl
>
> # startup.pl
> use strict;
> use warnings;
>
> use Mymodule;
> Mymodule->init;
>
> 1;
>
> ## Mymodule.pm
> package Mymodule;
>
> use strict;
> use warnings;
>
> our $data;
>
> sub new {
> ...
> }
>
> sub init {
> my $class = shift;
> $data = $class->new;
> }
>
> sub data {
> my $class = shift;
> return $data;
> }
>
> 1;
>
> then in your application you can access $data via $Mymodule::data, or
> better yet access it like so:
>
> my $data = Mymodule->data; # this returns the object created during
> # startup
>
> HTH,
>
> Fred
>
> > > > > -----Original Message-----
> > From: frank@wiles.org
> > To: pennyyh@aol.co.uk
> > CC: modperl@perl.apache.org
> > Sent: Tue, 25 Sep 2007 1.42AM
> > Subject: Re: load large data
> > > On Mon, 24 Sep 2007 06:08:45 -0400
> > pennyyh@aol.co.uk wrote:
> > >> Hello,
> >>
> >> I have a module,which loads large data into memory.
> >>
> >> my $data = Mymodule->new;
> >>
> >> this will take some ms to be finished.
> >>
> >> So I think I can create this object at startup time,and share the
> >> $data acrosss all apache child processes.
> >>
> >> Is it possible?How can I do it?
> > > Yeah you can do this in a <Perl> section at startup and
> > your children can then use it. I'm assuming here that the
> > info in $data doesn't change or that you're ok with having
> > to restart Apache to see the changes.
> > > -------------------------------------------------------
> > Frank Wiles, Revolution Systems, LLC.
> > Personal : frank@wiles.org http://www.wiles.org
> > Work : frank@revsys.com http://www.revsys.com
> > > > >
> ________________________________________________________________________
>
> > Check out the new free AOL Email -- 2GB of storage and
> industry-leading > spam and email virus protection.
>
>
>
> ________________________________________________________________________
> Check out the new free AOL Email -- 2GB of storage and industry-leading
> spam and email virus protection.
>
Re: load large data
Posted by pe...@aol.co.uk.
Thank you.
Sorry that module of Mymodule is a public module from CPAN.I can't
modify it to add the init() and data() methods.
How to do it then?thanks again.
-----Original Message-----
From: fred@redhotpenguin.com
To: pennyyh@aol.co.uk
CC: modperl@perl.apache.org
Sent: Tue, 25 Sep 2007 4.52PM
Subject: Re: load large data
pennyyh@aol.co.uk wrote:
> Thank you.
> I have added these directives in httpd.conf,
> > <Perl>
> use Mymodule;
> our $data = Mymodule->new;
> </Perl>
> > Then I run bin/apachectl configtest,but got the errors,
> > Unknown type 'Mymodule' for directive data at >
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache2/PerlSectio
> ns.pm line 192.\n
> > Please help.Thanks.
As with all Perl code, there is more than one way to do it. Another way
to accomplish what you are trying to do is through the use of
startup.pl, which is run during apache startup. (I don't know why that
error above is occurring so I'm posting this as an alternate approach).
# httpd.conf
PerlPostConfigRequire /home/pennyyh/perl/lib/startup.pl
# startup.pl
use strict;
use warnings;
use Mymodule;
Mymodule->init;
1;
## Mymodule.pm
package Mymodule;
use strict;
use warnings;
our $data;
sub new {
...
}
sub init {
my $class = shift;
$data = $class->new;
}
sub data {
my $class = shift;
return $data;
}
1;
then in your application you can access $data via $Mymodule::data, or
better yet access it like so:
my $data = Mymodule->data; # this returns the object created during
# startup
HTH,
Fred
> > > > -----Original Message-----
> From: frank@wiles.org
> To: pennyyh@aol.co.uk
> CC: modperl@perl.apache.org
> Sent: Tue, 25 Sep 2007 1.42AM
> Subject: Re: load large data
> > On Mon, 24 Sep 2007 06:08:45 -0400
> pennyyh@aol.co.uk wrote:
> >> Hello,
>>
>> I have a module,which loads large data into memory.
>>
>> my $data = Mymodule->new;
>>
>> this will take some ms to be finished.
>>
>> So I think I can create this object at startup time,and share the
>> $data acrosss all apache child processes.
>>
>> Is it possible?How can I do it?
> > Yeah you can do this in a <Perl> section at startup and
> your children can then use it. I'm assuming here that the
> info in $data doesn't change or that you're ok with having
> to restart Apache to see the changes.
> > -------------------------------------------------------
> Frank Wiles, Revolution Systems, LLC.
> Personal : frank@wiles.org http://www.wiles.org
> Work : frank@revsys.com http://www.revsys.com
> > > >
________________________________________________________________________
> Check out the new free AOL Email -- 2GB of storage and
industry-leading > spam and email virus protection.
________________________________________________________________________
Check out the new free AOL Email -- 2GB of storage and industry-leading
spam and email virus protection.
Re: load large data
Posted by Fred Moyer <fr...@redhotpenguin.com>.
pennyyh@aol.co.uk wrote:
> Thank you.
> I have added these directives in httpd.conf,
>
> <Perl>
> use Mymodule;
> our $data = Mymodule->new;
> </Perl>
>
> Then I run bin/apachectl configtest,but got the errors,
>
> Unknown type 'Mymodule' for directive data at
> /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache2/PerlSectio
> ns.pm line 192.\n
>
> Please help.Thanks.
As with all Perl code, there is more than one way to do it. Another way
to accomplish what you are trying to do is through the use of
startup.pl, which is run during apache startup. (I don't know why that
error above is occurring so I'm posting this as an alternate approach).
# httpd.conf
PerlPostConfigRequire /home/pennyyh/perl/lib/startup.pl
# startup.pl
use strict;
use warnings;
use Mymodule;
Mymodule->init;
1;
## Mymodule.pm
package Mymodule;
use strict;
use warnings;
our $data;
sub new {
...
}
sub init {
my $class = shift;
$data = $class->new;
}
sub data {
my $class = shift;
return $data;
}
1;
then in your application you can access $data via $Mymodule::data, or
better yet access it like so:
my $data = Mymodule->data; # this returns the object created during
# startup
HTH,
Fred
>
>
>
> -----Original Message-----
> From: frank@wiles.org
> To: pennyyh@aol.co.uk
> CC: modperl@perl.apache.org
> Sent: Tue, 25 Sep 2007 1.42AM
> Subject: Re: load large data
>
> On Mon, 24 Sep 2007 06:08:45 -0400
> pennyyh@aol.co.uk wrote:
>
>> Hello,
>>
>> I have a module,which loads large data into memory.
>>
>> my $data = Mymodule->new;
>>
>> this will take some ms to be finished.
>>
>> So I think I can create this object at startup time,and share the
>> $data acrosss all apache child processes.
>>
>> Is it possible?How can I do it?
>
> Yeah you can do this in a <Perl> section at startup and
> your children can then use it. I'm assuming here that the
> info in $data doesn't change or that you're ok with having
> to restart Apache to see the changes.
>
> -------------------------------------------------------
> Frank Wiles, Revolution Systems, LLC.
> Personal : frank@wiles.org http://www.wiles.org
> Work : frank@revsys.com http://www.revsys.com
>
>
>
> ________________________________________________________________________
> Check out the new free AOL Email -- 2GB of storage and industry-leading
> spam and email virus protection.
Re: load large data
Posted by pe...@aol.co.uk.
Thank you.
I have added these directives in httpd.conf,
<Perl>
use Mymodule;
our $data = Mymodule->new;
</Perl>
Then I run bin/apachectl configtest,but got the errors,
Unknown type 'Mymodule' for directive data at
/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/Apache2/PerlSectio
ns.pm line 192.\n
Please help.Thanks.
-----Original Message-----
From: frank@wiles.org
To: pennyyh@aol.co.uk
CC: modperl@perl.apache.org
Sent: Tue, 25 Sep 2007 1.42AM
Subject: Re: load large data
On Mon, 24 Sep 2007 06:08:45 -0400
pennyyh@aol.co.uk wrote:
> Hello,
>
> I have a module,which loads large data into memory.
>
> my $data = Mymodule->new;
>
> this will take some ms to be finished.
>
> So I think I can create this object at startup time,and share the
> $data acrosss all apache child processes.
>
> Is it possible?How can I do it?
Yeah you can do this in a <Perl> section at startup and
your children can then use it. I'm assuming here that the
info in $data doesn't change or that you're ok with having
to restart Apache to see the changes.
-------------------------------------------------------
Frank Wiles, Revolution Systems, LLC.
Personal : frank@wiles.org http://www.wiles.org
Work : frank@revsys.com http://www.revsys.com
________________________________________________________________________
Check out the new free AOL Email -- 2GB of storage and industry-leading
spam and email virus protection.
Re: load large data
Posted by Frank Wiles <fr...@wiles.org>.
On Mon, 24 Sep 2007 06:08:45 -0400
pennyyh@aol.co.uk wrote:
> Hello,
>
> I have a module,which loads large data into memory.
>
> my $data = Mymodule->new;
>
> this will take some ms to be finished.
>
> So I think I can create this object at startup time,and share the
> $data acrosss all apache child processes.
>
> Is it possible?How can I do it?
Yeah you can do this in a <Perl> section at startup and
your children can then use it. I'm assuming here that the
info in $data doesn't change or that you're ok with having
to restart Apache to see the changes.
-------------------------------------------------------
Frank Wiles, Revolution Systems, LLC.
Personal : frank@wiles.org http://www.wiles.org
Work : frank@revsys.com http://www.revsys.com
Re: load large data
Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
pennyyh@aol.co.uk wrote:
> Hello,
>
> I have a module,which loads large data into memory.
>
> my $data = Mymodule->new;
>
> this will take some ms to be finished.
And consume large amounts of RAM too I would imagine.
> So I think I can create this object at startup time,and share the $data
> acrosss all apache child processes.
>
> Is it possible?How can I do it?
Yes, possible. Just assign the data to a named global at startup time.
ie.
<httpd.conf>
PelrModule My::Module
</httpd.conf>
<My/Module.pm>
package My::Module;
use Mymodule;
our $data = Mymodule->new;
</My/Module.pm>
Than anywhere you want, just refer to $My::Module::data
Generally, when doing something like that, you want to make 100% certain
that your data is read-only, otherwise, any changes to it won't be reflected
for every child process, and tons of memory will get suddently unshared.
To avoid that, checkout the various ways you can make something truly
read-only. (Hash::Util::lock_hash, Readonly.pm, etc)
------------------------------------------------------------------------
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/