Re: hashes and mod_perl

2000-10-31 Thread Perrin Harkins

On Tue, 31 Oct 2000, Scott Alexander wrote:
> Is it in anyway possible to tie the hash once to a dbm file?
> 
> At the moment it is tied every time a script is called. 

There's a whole chapter on this: http://perl.apache.org/guide/dbm.html.

The short answer is that you have to tie the dbm file once in every child,
but only once.

- Perrin




Re: hashes and mod_perl

2000-10-31 Thread Scott Alexander



> Hi there,
> 
> On Tue, 31 Oct 2000, Scott Alexander wrote:
> 
> > Is it possible using the magic of mod_perl to set a hash array
> > available for all scripts without each script having to open the dbm
> > file.
> 
> It's not really a mod_perl specific problem.  You need to take care of
> the possibility that there will be conflicts between processes trying
> to write to the same file, so you need to implement some sort of
> locking.  It's in the Guide .

I'm using the hash to store different output languages and is only 
ever updated by one person. 100% of the time it's being read.

>  
> > In some of my scripts I'm using functions recursively. Passing
> > %output to a function will work once put when it goes very deep
> > recursively it doesn't work.
> 
> Pass a reference.
> 
> my $rhash = \%output;
> my $result = func( $rhash );

Okay this solves my problem that I had.

> 
> $rhash _could_ be a global, but don't go there...



Is it in anyway possible to tie the hash once to a dbm file?

At the moment it is tied every time a script is called. 

Does the line $test = dbmopen(%output, "/my.dbm", 0600) ; on 
every script cause much work?

Scott

> 
> 73,
> Ged.





Re: hashes and mod_perl

2000-10-31 Thread G.W. Haywood

Hi again,

> > Pass a reference.
> > my $rhash = \%output;
> > my $result = func( $rhash );
> 
> Okay this solves my problem that I had.
> Is it in anyway possible to tie the hash once to a dbm file?
> At the moment it is tied every time a script is called. 

Sounds like you haven't really got to grips with handlers, and your
script is written in a cgi-like fashion.  You want mod_perl to load
the script once at startup, then just execute the things that need
executing when a handler is called.  Read the Guide.  I'm sorry it's
such a forbidding document thesedays, but it's really worth it.  Read
the Eagle Book too.  Then read it all again (unless your ability to
absorb densely packed information is absolutely astounding:).

> Does the line $test = dbmopen(%output, "/my.dbm", 0600) ; on 
> every script cause much work?

It depends what you mean by 'not much'.  Opening and closing files is
one of the life-blood activities of the operating system, so lots of
work has gone into making it as slick as possible.  But it still takes
more time than referring to areas of data directly in memory because
there's more to do and because the physics of storage is different.
What matters is how often your script gets called, and whether the
computer can keep ahead of its tasks under maximum load.  Someone who
serves, say, a hundred training courses to 400,000 users may go to
great lengths to cut execution times, but it might be that it doesn't
matter in your case.  Or you might get a kick out of tuning systems.
Only you can be the judge of that.

There are utilities out there to test performance, after a fashion.
Look at ab which comes with Apache when you install it.  But don't
forget that when Apache is serving pages, mod_perl or not, it's not
just your script that's doing the work.  It's a very complex system
that you're dealing with, which probably includes a worldwide network,
a bunch of communications devices and a browser, running on hardware
you've never seen and never will.

See also the thread "how to really bang on a script" in this list
which has some more references and some entertaining insights.  The
ISBN for the Eagle Book is in one of my posts on that thread.

73,
Ged.





Re: hashes and mod_perl

2000-10-31 Thread G.W. Haywood

Hi there,

On Tue, 31 Oct 2000, Scott Alexander wrote:

> Is it possible using the magic of mod_perl to set a hash array
> available for all scripts without each script having to open the dbm
> file.

It's not really a mod_perl specific problem.  You need to take care of
the possibility that there will be conflicts between processes trying
to write to the same file, so you need to implement some sort of
locking.  It's in the Guide .
 
> In some of my scripts I'm using functions recursively. Passing
> %output to a function will work once put when it goes very deep
> recursively it doesn't work.

Pass a reference.

my $rhash = \%output;
my $result = func( $rhash );

$rhash _could_ be a global, but don't go there...

73,
Ged.