Re: How to pre-open files in apache's processes

Torsten Förtsch <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
On Thursday, December 02, 2010 14:26:36 Xiao Lan wrote:
> > But, looking at the module I think it can be slow because it relies
> > heavily on seek(). A better approach would be to mmap() the file. In
> > perl it would look then like a big string. My favourite tool for that is
> > File::Map.
> 
> OK thanks for this info. I will take a look at File::Map.

If I were you, I'd really consider to convert the database into an MMapDB, see 
http://search.cpan.org/perldoc?MMapDB

You can create the MMapDB object in a <Perl> section in the httpd.conf or in a 
ChildInit handler or something similar:

  <Perl>
    use MMapDB;
    # use a global variable here to make it accessible from everywhere
    $My::DB=MMapDB->new(filename=>..., readonly=>1);
  </Perl>

Then in your handler (simplest case):

  use MMapDB qw/:mode/;
  $My::MMapDB->start;   # update the object if the database file has changed
  $My::DB->datamode=DATAMODE_SIMPLE;
  ($value)=@{$My::DB->main_index->{$key} || []};

If the extra step of converting the QQWry.Dat into a QQWry.mmdb can be built 
into your work flow that would be the route I'd take.

Otherwise I'd look for a C library to that database and build a perl interface 
layer in XS.

Torsten Förtsch

-- 
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.