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 02:24:32 Xiao Lan wrote:
> I was giving the example by openning a file.
> In acutal I was using this module:
>
> http://search.cpan.org/~sunnavy/IP-QQWry-0.0.16/lib/IP/QQWry.pm
>
> For each client request if I open the data file:
>
> my $qqwry = IP::QQWry->new('QQWry.Dat');
>
> That will be slow IMO.
>
> So I was thinking to pre-open the data file in each process of apache
> and use it directly in each handler.
I don't think the module is slow because of opening a file, especially on
local disk. Apache does that all the time.
On the other hand there should be no problem with opening a file and keeping
it open over the lifetime of the apache child. Apache itself does that. It
opens its logfiles only once. Also, modperl applications often cache database
connections. That means the database socket is opened only once for multiple
requests. The only thing to think about is what happens if the database is
updated. If the original file is removed and a new one is written you'll still
keep the old one. If the original file is written to any index that you keep
in RAM may be invalid.
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.
Torsten Förtsch
--
Need professional modperl support? Hire me! (http://foertsch.name)
Like fantasy? http://kabatinte.net