Skip to content

Instantly share code, notes, and snippets.

@adokoy001
Created July 11, 2016 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adokoy001/5ea1c7027f3371c4bfc555131b1b0618 to your computer and use it in GitHub Desktop.
Save adokoy001/5ea1c7027f3371c4bfc555131b1b0618 to your computer and use it in GitHub Desktop.
MapReduce::Framework::Simple Benchmark example.
use strict;
use warnings;
my $sum = 0;
for(1 .. 3_000_000_000){
$sum += $_;
}
print $sum,"\n";
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";
$ 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