A threaded 'find' library?

D

Daniel Berger

Hi all,

The recent talk of threaded access to a file made me wonder if I could
do the same with a file searching lib (file-find in my case). This is
the basic logic:

paths.each{ |path|
Dir.foreach(path){ |file|
paths << file if file is a directory (and not already searched)
next unless file matches user-supplied pattern
}
}

I thought I setting up a thread queue and spawning a new thread for each
new directory would speed it up, but my (probably poor) attempts to
implement it did not result in any speed improvements, and usually
slowed it down a little bit.

Any suggestions?

Thanks,

Dan
 
M

Michal Suchanek

Hi all,

The recent talk of threaded access to a file made me wonder if I could
do the same with a file searching lib (file-find in my case). This is
the basic logic:

paths.each{ |path|
Dir.foreach(path){ |file|
paths << file if file is a directory (and not already searched)
next unless file matches user-supplied pattern
}
}

I thought I setting up a thread queue and spawning a new thread for each
new directory would speed it up, but my (probably poor) attempts to
implement it did not result in any speed improvements, and usually
slowed it down a little bit.

That's because ruby does not really support concurrent threads. Any
overhead you add by threading only slows things down. And after you
run the program for the first time you probably have most of the
directories cached so you cannot cover any waiting for io with threads
either.

To fake the delay you could put a sleep in front of calling
Dir.foreach. This is where the directory would be likely opened and
the filesystem might need to fetch a block or two.

You can also perform a test with a floppy, just unmount, eject, and
remount it each time to make sure the cache is invalidated :)

Thanks

Michal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,269
Messages
2,571,348
Members
48,026
Latest member
ArnulfoCat

Latest Threads

Top