Syntactic Confectionery Delight | |
PerlMonks |
Re: Wait for individual sub processesby marioroy (Prior) |
on Apr 25, 2015 at 12:30 UTC ( [id://1124673]=note: print w/replies, xml ) | Need Help?? |
The following is an example using MCE to process a file. Splitting the file into parts before running is not necessary. Chunking is integrated into MCE allowing for maximum CPU utilization from start to end. Update 1: Added merge_to_iter to merge the output into one file while preserving order. Update 2: $slurp_ref is a scalar reference, thus print $fh $$slurp_ref; Update 3: Changed chunk_size from 'auto' to 200. A chunk size smaller than or equal to 8192 is the number of records (or # of lines). A value greater than 8192 is the number of bytes with MCE reading until the end of record. MCE quietly sets to 64M if higher than 64M. The OP provided timings with 100 rows taking ~ 1 minute. Update 4: Changed max_workers from 'auto' to 16. The 'auto' value will never go higher than 8. Thus, one must set explicitly if wanting to run on all available cores or with max_workers => MCE::Util::get_ncpu().
In Section
Seekers of Perl Wisdom
|
|