perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Hedges <hed...@scriptdolphin.org>
Subject Re: Initializing Sleepycat::DbXml (Berkeley, Oracle) objects in startup.pl
Date Wed, 14 Jan 2009 16:18:51 GMT


On Wed, 14 Jan 2009, Michael Ludwig wrote:

> I want to build a mod_perl2 application using
> Sleepycat::DbXml. This is
>
> However, I don't know how to do this. Currently, I'm
> trying to set up things in startup.pl (loaded via
> PerlPostConfigRequire), store the database environment
> handle in a global package variable, and access that from
> the PerlContentHandler.

This probably won't work since the filehandle cannot be
shared among mod_perl children.

Your startup.pl script is running before the root apache
process forks into the child processes.  Scalars, lists and
hashes will be cloned, but file handles won't, they have to
be opened.

Probably what you're thinking of is a PerlChildInitHandler
so that each mod_perl child process does your connection for
you when the child process first forks.

Or, you can use it like this in a handler, essentially the
same thing:

 package YourResponseHandler;
 use strict;
 use warnings FATAL => 'all';

 use SleepyCat::DbXml qw(simple);

 # is this the way it works?  i trolled for it...
 # where is the manual page??  ugh
 my $container = XmlContainer->new('/path/to/whatever.xml');

 sub handler {
     my ($r) = @_;
     $container->open(Db::DB_CREATE);
     $container->put...
     # ...
     $container->close();  # ?? not sure how it works
 }

But it's not clear how much time you're going to save. I
don't know how the thing works.  You may or may not be able
to call open() from package scope because of locking, are
locks on the sleepycat database serial? If so then every
mod_perl child process is going to be waiting for the others
to complete before they can establish their own locks and
there's no way around that. You'll have to balance how many
writes you expect to get with how many reads, maybe reading
actions do not require locks on the data file.

Mark


Mime
View raw message