Don't ask to ask, just ask | |
PerlMonks |
Re: use threads for dir tree walking really hurtsby Corion (Patriarch) |
on Aug 31, 2016 at 13:29 UTC ( [id://1170882]=note: print w/replies, xml ) | Need Help?? |
Why are you doing that? Perl is not C and you don't need to step outside the Perl datatypes to handle data access from multiple threads within Perl. The following should be the equivalent of what you do, except far saner and not needing Devel::Pointer:
Note that you do not even start running multiple threads in the above because you spawn a separate thread but don't continue until it has finished its work. Most likely, a better approach is to store all threads and then wait for them to finish:
Personally, I recommend using Thread::Queue and a worker pool to handle a workload because starting a Perl thread is relatively resource intensive. I'm not sure that using multiple threads will bring you much benefit, as I think your operation largely is limited by the network or the HD (or filesystem) performance. Thinking more about it, I guess that a somewhat better approach is to have all directories to crawl stored in a Thread::Queue and to have threads fetch from that whenever they need to crawl a new directory. For output, I would use another Thread::Queue, just for simplicissity (roughly adapted from here:
In Section
Seekers of Perl Wisdom
|
|