Robert Klemme
1/8/2008 1:04:00 PM
2008/1/8, Alex Maccaw <maccman@gmail.com>:
> I have a file based msg queue, and msgs are stored five folders down.
>
> When a request for the next msg is received, I need to grab the first
> file I can find, as fast as I can.
>
> I've tried Dir.glob, and only selecting the first file. This however is
> an awful way of doing it as it loads every file into memory, before
> selecting the first.
>
> A bit better is Find.find, which finds files incrementally. However,
> this still takes about 0.005 seconds (I presume since it's also
> 'finding' directories').
>
> Is there a faster way to do this?
You find 5ms when accessing the file system long? I'd say that's
pretty fast considering what you do (recursive search). I doubt you
will get much improvement as long as you always access the file system
for your search. If you know the change frequency of files then you
could store file system contents in memory and only update every n
seconds / minutes or whatever or have a background thread that
continuously updates your in memory representation.
Kind regards
robert
--
use.inject do |as, often| as.you_can - without end