A very powerful and easy to use Perl multitasking module.
Used in every single code I now write, as it’s annoying to continuously update code just to make it scale-able. In my scripts I usually like to “fork” things off especially say when manipulating data.
With this module it’s as easy as a foreach loop:
use Parallel::ForkManager;
use PiroLabs::Utils::DataCruncher;
my $max_threads = 10;
my @tasks = qw (x / + -);
$pm = new Parallel::ForkManager($max_threads);
foreach (@tasks){
$pm = new Parallel::ForkManager($max_threads);
my $pid = $pm->start and next;
my $dc = new DataCruncher([0 … 2000000], $_);
$dc->Execute();
$pm->finish;
}
$pm->wait_all_children;
In the snippet above I want to perform multiplication, division, addition and subtraction all at the same time on some defined data set.
Next post I will show how to pass data from the child processes back to the parent.