Changeset 232972 in webkit


Ignore:
Timestamp:
Jun 19, 2018 11:59:51 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Test262-Runner: Improve files queue to optimize CPU usage/balancing
https://bugs.webkit.org/show_bug.cgi?id=186443

Patch by Leo Balter <Leo Balter> on 2018-06-19
Reviewed by Michael Saboff.

This patch creates a queue manager for to keep the child process open while the parent process feed each child with test files to run.

  • Scripts/test262/Runner.pm:

(processCLI):
(main):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r232968 r232972  
     12018-06-19  Leo Balter  <leonardo.balter@gmail.com>
     2
     3        Test262-Runner: Improve files queue to optimize CPU usage/balancing
     4        https://bugs.webkit.org/show_bug.cgi?id=186443
     5
     6        Reviewed by Michael Saboff.
     7
     8        This patch creates a queue manager for to keep the child process open while the parent process feed each child with test files to run.
     9        * Scripts/test262/Runner.pm:
     10        (processCLI):
     11        (main):
     12
    1132018-06-19  Wenson Hsieh  <wenson_hsieh@apple.com>
    214
  • trunk/Tools/Scripts/test262/Runner.pm

    r232906 r232972  
    4343use Config;
    4444use Time::HiRes qw(time);
     45use IO::Handle;
     46use IO::Select;
    4547
    4648my $Bin;
     
    7577
    7678# Commandline settings
    77 my $max_process;
     79my $maxProcesses;
    7880my @cliTestDirs;
    7981my $verbose;
     
    127129        't|t262=s' => \$test262Dir,
    128130        'o|test-only=s@' => \@cliTestDirs,
    129         'p|child-processes=i' => \$max_process,
     131        'p|child-processes=i' => \$maxProcesses,
    130132        'h|help' => \$help,
    131133        'release' => \$release,
     
    256258    }
    257259
    258     $max_process ||= getProcesses();
     260    $maxProcesses ||= getProcesses();
    259261
    260262    print "\nSettings:\n"
    261263        . "Test262 Dir: " . abs2rel($test262Dir) . "\n"
    262264        . "JSC: " . abs2rel($JSC) . "\n"
    263         . "Child Processes: $max_process\n";
     265        . "Child Processes: $maxProcesses\n";
    264266
    265267    print "Test timeout: $timeout\n" if $timeout;
     
    278280    print "---\n\n";
    279281}
    280 
    281282
    282283sub main {
     
    314315    }
    315316
    316     # If we are processing many files, fork process
    317     if (scalar @files > $max_process * 5) {
     317    my $pm = Parallel::ForkManager->new($maxProcesses);
     318    my $select = IO::Select->new();
     319
     320    my @children;
     321    my @parents;
     322    my $activeChildren = 0;
     323
     324    my @resultsfhs;
     325
     326    # Open each process
     327    PROCESSES:
     328    foreach (0..$maxProcesses-1) {
     329        my $i = $_;
    318330
    319331        # Make temporary files to record results
    320         my @resultsfhs;
    321         for (my $i = 0; $i <= $max_process-1; $i++) {
    322             my ($fh, $filename) = getTempFile();
    323             $resultsfhs[$i] = $fh;
    324         }
    325 
    326         my $pm = Parallel::ForkManager->new($max_process);
    327         my $filesperprocess = int(scalar @files / $max_process);
    328 
    329         FILES:
    330         for (my $i = 0; $i <= $max_process-1; $i++) {
    331             $pm->start and next FILES; # do the fork
    332             srand(time ^ $$); # Creates a new seed for each fork
    333 
    334             my $first = $filesperprocess * $i;
    335             my $last = $i == $max_process-1 ? scalar @files : $filesperprocess * ($i+1);
    336 
    337             for (my $j = $first; $j < $last; $j++) {
    338                 processFile($files[$j], $resultsfhs[$i]);
    339             };
    340 
    341             $pm->finish; # do the exit in the child process
    342         };
    343 
    344         $pm->wait_all_children;
    345 
    346         # Read results from file into @results and close
    347         for (my $i = 0; $i <= $max_process-1; $i++) {
    348             seek($resultsfhs[$i], 0, 0);
    349             push @results, LoadFile($resultsfhs[$i]);
    350             close $resultsfhs[$i];
    351         }
    352     }
    353     # Otherwising, running sequentially is fine
    354     else {
    355         my ($resfh, $resfilename) = getTempFile();
    356         foreach my $file (@files) {
    357             processFile($file, $resfh);
    358         };
    359         seek($resfh, 0, 0);
    360         @results = LoadFile($resfh);
    361         close $resfh;
     332        my ($fh, $filename) = getTempFile();
     333        $resultsfhs[$i] = $fh;
     334
     335        socketpair($children[$i], $parents[$i], 1, 1, 0);
     336        my $child = $children[$i];
     337        my $parent = $parents[$i];
     338        $child->autoflush(1);
     339        $parent->autoflush(1);
     340
     341        # seeds each child with a file;
     342
     343        my $pid = $pm->start;
     344        if ($pid) { # parent
     345            $select->add($child);
     346            # each child starts with a file;
     347            my $file = shift @files;
     348            chomp $file;
     349            if ($file) {
     350                print $child "$file\n";
     351                $activeChildren++;
     352            }
     353
     354            next PROCESSES;
     355        }
     356
     357        # children will start here
     358        srand(time ^ $$); # Creates a new seed for each fork
     359        CHILD:
     360        while (<$parent>) {
     361            my $file = $_;
     362            chomp $file;
     363            if ($file eq 'END') {
     364                last;
     365            }
     366
     367            processFile($file, $resultsfhs[$i]);
     368            print $parent "signal\n";
     369        }
     370
     371        $child->close();
     372        $pm->finish;
     373    }
     374
     375    my @ready;
     376    FILES:
     377    while ($activeChildren and @ready = $select->can_read($timeout)) {
     378        foreach (@ready) {
     379            my $readyChild = $_;
     380            my $childMsg = <$readyChild>;
     381            chomp $childMsg;
     382            $activeChildren--;
     383            my $file = shift @files;
     384            if ($file) {
     385                chomp $file;
     386                print $readyChild "$file\n";
     387                $activeChildren++;
     388            } elsif (!$activeChildren) {
     389                last FILES;
     390            }
     391        }
     392    }
     393
     394    foreach (@children) {
     395        print $_ "END\n";
     396    }
     397
     398    foreach (@parents) {
     399        $_->close();
     400    }
     401
     402    my $count = 0;
     403    for my $parent (@parents) {
     404        my $child = $children[$count];
     405        print $child "END\n";
     406        $parent->close();
     407        $count++;
     408    }
     409
     410    $pm->wait_all_children;
     411
     412    # Read results from file into @results and close
     413    foreach (0..$maxProcesses-1) {
     414        my $i = $_;
     415        seek($resultsfhs[$i], 0, 0);
     416        push @results, LoadFile($resultsfhs[$i]);
     417        close $resultsfhs[$i];
    362418    }
    363419
     
    10361092=item B<--child-processes, -p>
    10371093
    1038 Specify number of child processes.
     1094Specify the number of child processes.
    10391095
    10401096=item B<--t262, -t>
Note: See TracChangeset for help on using the changeset viewer.