=pod # $ DISPLAY=:99 perl script.pl You need to set the C env variable because this script uses headless Firefox instances run by Selenium. =cut use strict; use warnings; use MCE::Shared; use MCE::Loop; use Tie::Cycle; my $pid = $$; END { report() if $$ == $pid } # only parent process reports results # Overall results hash, shared between processes my $results = MCE::Shared->hash(); # Process the data my %data = get_data(); # in this case, was keyed by HTTP method for my $method ( keys %data ) { MCE::Loop->init( chunk_size => 100, max_workers => 8 ); tie my $screen, 'MCE::Shared', { module => 'Tie::Cycle' }, [ 0 .. 7 ]; # We have a fixed number of screens in our virtual X buffer; # this range should match the number of MCE worker processes mce_loop { my ( $mce, $chunk_ref, $chunk_id ) = @_; my $driver = get_selenium_driver(); # or maybe an obj that already knows what SRD commands to run # Set the screen ID for a Firefox instance (for Selenium) $ENV{'DISPLAY'} = ':99.' . $screen; for ( @{ $chunk_ref } ) { my %this_job_data = %{ $_ }; if ( $this_job_data{skip} ) { $results->incr('SKIP'); next; } $driver->do_the_thing( $this_job_data ); $results->incr('OK'); $results->incr($this_job_data->{something}); } } @{ $data{ $method } }; MCE::Loop->finish; } ## sub report { # do something with $results } __END__