[LA.pm] perl CGI querying of directory filenames most efficient method?
Jeremy Leader
jleader at alumni.caltech.edu
Thu Sep 22 15:10:23 PDT 2005
Peter Benjamin wrote:
> Questions:
>
> Does the Unix File Cache also cache directory
> information? I imagine it does, so this CGI script would
> not have to access the hard drive to get the list of files,
> but just get it from RAM, for each and every -e test,
> or for the foreach, or readdir methods.
Think of it as a disk cache, rather than a file cache.
That is, it caches recently accessed disk blocks, whether
they belong to files or directories.
> Would the -e test have to go to the hard drive each time?
> Or would the entire directory 'file' be in the File Cache
> as well in that case? Which would mean both methods are
> efficient, and either would do fine.
Yes, I'd expect the directory blocks to be cached, unless
the directory was really huge or there was a whole lot of
other disk access going on at the same time. What does
"ls -sd $dir" give as the number of blocks in the directory?
> I might do a comparison testing in a loop, but then that
> would not simulate a CGI script, unless the script was
> invoked by an outer loop coded in a shell script to
> create new PIDs each time (avoid using the directory
> contents that would be "buffered" in File IO cache,
> or even in the perl buffers).
>
> What comparison testing method would you use?
>
> Right now it is "cheaper" programmer time wise to do -e
> testing than add a database field to store the values,
> which one might imagine would be faster , but even then
> the directory contents needs to be accessed in order
> to web serve the image, and having the directory
> contents in File Cache due to the web server using
> it means the database field might not be any faster
> than either the if-elsif-else or foreach methods.
If the web server is opening these files (to serve their
contents), then the -e tests won't add much cost, I
believe.
--
Jeremy Leader
jleader at alumni.caltech.edu
leaderj at yahoo-inc.com (work)
More information about the Losangeles-pm
mailing list