in reply to MCE: Slow IPC between child and gather process in parent
Hi learnedbyerror,
How is $output defined and populated? It's not shown in the code. Being on a Mac, is the folder where the output file resides disabled from Spotlight indexing? E.g. Apple Menu -> System Preferences -> Spotlight -> Privacy Tab
MCE Relay may be helpful to factor out freeze/thaw operations for large data. Please find below two demonstrations for solely testing IPC. The Gather and Relay demonstrations take 11.3 and 12.1 seconds respectively for 1 million iterations. Both handle above 50k iterations per second.
Iterator & Gather demonstration
use strict; use warnings; use MCE; use MCE::Candy; use Time::HiRes 'time'; # usage: script_gather.pl [ N ] open my $fh_out, ">:utf8", "output.txt"; my $mce = MCE->new( gather => MCE::Candy::out_iter_fh($fh_out), max_workers => 3, user_func => \&user_func, )->spawn; my $start = time; $mce->process( make_iterator( shift || 1000 ) ); my $duration = time - $start; $mce->shutdown; close $fh_out; printf "duration: %0.3f\n", $duration; sub make_iterator { my $max_id = shift; my $nxt_id = 0; return sub { return if $nxt_id >= $max_id; return ++$nxt_id; }; } sub user_func { my ( $mce, $chunk_ref, $chunk_id ) = @_; my $output = $chunk_ref->[0]."\n"; MCE->gather($chunk_id, $output); }
Iterator & Relay demonstration
use strict; use warnings; use MCE; use Time::HiRes 'time'; # usage: script_relay.pl [ N ] open my $fh_out, ">:utf8", "output.txt"; $fh_out->autoflush(1); my $mce = MCE->new( init_relay => 0, max_workers => 3, user_func => \&user_func, )->spawn; my $start = time; $mce->process( make_iterator( shift || 1000 ) ); my $duration = time - $start; $mce->shutdown; close $fh_out; printf "duration: %0.3f\n", $duration; sub make_iterator { my $max_id = shift; my $nxt_id = 0; return sub { return if $nxt_id >= $max_id; return ++$nxt_id; }; } sub user_func { my ( $mce, $chunk_ref, $chunk_id ) = @_; my $output = $chunk_ref->[0]."\n"; MCE::relay { print {$fh_out} $output }; }
Update: Changed max_workers from 'auto' to 3 above. Basically, try 3 ~ 5 workers as the OP's example involves lots of IO. The MCE module was written in a way to handle thousands of IPC requests per second. For such examples that do 10's of thousands IPC requests, limiting the number of workers allows the OS to allocate more CPU time for the manager process. Chunking is another way.
Regards, Mario
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: MCE: Slow IPC between child and gather process in parent
by learnedbyerror (Monk) on May 02, 2018 at 16:41 UTC | |
|
Re^2: MCE: Slow IPC between child and gather process in parent
by marioroy (Prior) on May 06, 2018 at 19:20 UTC | |
by marioroy (Prior) on May 07, 2018 at 02:19 UTC | |
by learnedbyerror (Monk) on May 07, 2018 at 12:59 UTC | |
by learnedbyerror (Monk) on May 07, 2018 at 13:06 UTC |