Im trying to use Parallel::ForkManager to split off some slow processes in hopes of increasing overall performance. The 'main' task is one that should lend itself well to parallel activity: examining 'client data' in a db by way of 10-15 queries each of which reports some value. There are ~100 'clients' in the db. The current application takes each client in sequence, runs the series of queries and saves the results in a table.
The vast majority of the processing time is spent waiting for the DB server. The server is running MySQL on an 8 way box with 8G of RAM. The box running the application(s) is a dual core with 1G of RAM.
Here's what I did and what confused me:
I used the sample(s) from Parallel::ForkManager to rewrite my app so that instead of looping through the list of available 'clients' it gets them all in an array and calls
foreach $row ( @{$ref} ) {
my $pid = $pm->start(@$row->[0]) and next;
my $out = `./alert_main.pl -h $row->[0] -p $passId`;
print $out;
print "\n";
$pm->finish($row);
}
So it spins off the number of processes that ForkManager is called with, each runs, exits and the next one starts. I see it doing its work via the callbacks that ForkManager provides. All well and good. Here's where Im confused:
I run the application with 'max_procs' set to 1 and I get a total run time thats equivalent to my old 'one at a time' method. When I change 'max_procs' to 8 it takes more than
4 times longer to complete. I watch the CPU activity on the DB box and MySQL is (apparently) using all 8 procs. The total load runs at around 600%. The box that the app is running on never goes above 5%.
What am I doing wrong?