Created
July 11, 2016 08:07
-
-
Save adokoy001/5ea1c7027f3371c4bfc555131b1b0618 to your computer and use it in GitHub Desktop.
MapReduce::Framework::Simple Benchmark example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
my $sum = 0; | |
for(1 .. 3_000_000_000){ | |
$sum += $_; | |
} | |
print $sum,"\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use MapReduce::Framework::Simple; | |
my $mfs = MapReduce::Framework::Simple->new( | |
skip_undef_result => 1, | |
die_discarded_data => 1, | |
warn_discarded_data => 1 | |
); | |
my $data_map_reduce = [ | |
[[{start => 1, end => 1_000_000_000}],'http://remote01.example.com:5000/eval'], | |
[[{start => 1_000_000_001, end => 2_000_000_000}],'http://remote02.example.com:5000/eval'], | |
[[{start => 2_000_000_001, end => 3_000_000_000}],'http://remote03.example.com:5000/eval'] | |
]; | |
# mapper code | |
my $mapper = sub { | |
my $input = shift; | |
my $start = $input->[0]->{start}; | |
my $end = $input->[0]->{end}; | |
my $sum=0; | |
for($start .. $end){ | |
$sum += $_; | |
} | |
return($sum); | |
}; | |
# reducer code | |
my $reducer = sub { | |
my $input = shift; | |
my $sum = 0; | |
for(0 .. $#$input){ | |
$sum += $input->[$_]; | |
} | |
return($sum); | |
}; | |
my $result = $mfs->map_reduce( | |
$data_map_reduce, | |
$mapper, | |
$reducer, | |
4, | |
{remote => 1} | |
); | |
print $result,"\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ time perl bench_sum.pl | |
4500000001500000000 | |
perl bench_sum.pl 127.15s user 0.04s system 99% cpu 2:07.38 total | |
$ time perl mapr_framework.pl | |
4500000001500000000 | |
perl mapr_framework.pl 0.22s user 0.04s system 0% cpu 42.243 total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment