in reply to Re^2: Perl and autoparallelization
in thread Perl and autoparallelization

I'd use one worker thread per processor and a Thread::Queue of the files to be processed. The main thread sets up (or feeds, if the list is very large eg. >~10,000) the Q with the files to be processed.

The threads take the first file off the Q, process it and then loop back and get the next until the Q is empty.

This is extremely simple to code and since 5.8.3 appears to be very stable as far as memory consumption is concerned, though I haven't run any really long runs using Thread::Queue.

Once the threads are spawned, no new threads or processes need to to be created or destroyed which make it pretty efficient. All the sharing and locking required is taken care of by the tested and proven Thread::Queue module.

I might try varying the number of threads up and down to see what gave the optimal throughput.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail