2.27 MapReduce Shuffle过程如何在Job中进行设置
一、shuffle过程
总的来说:
*分区
- partitioner
*排序
- sort
*copy (用户无法干涉)
- 拷贝
*分组
- group
可设置
*压缩
- compress
*combiner
- map task端的Reduce
二、示例
package com.ibeifeng.hadoop.senior.mapreduce; import java.io.IOException;
import java.util.StringTokenizer; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; /**
* mapreduce
*
* @author root
*
*/
public class ModuleMapReduce extends Configured implements Tool {
// step1: map class
/**
* public class Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT>
*
*/
//TODO
public static class ModuleMapper extends
Mapper<LongWritable, Text, Text, IntWritable> { @Override
public void setup(Context context) throws IOException,
InterruptedException {
//Nothing
} @Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException { //TODO
} @Override
public void cleanup(Context context) throws IOException,
InterruptedException {
//Nothing
} } // step2: reduce class
/**
* public class Reducer<KEYIN,VALUEIN,KEYOUT,VALUEOUT>
*
*/
public static class ModuleReducer extends
Reducer<Text, IntWritable, Text, IntWritable> { @Override
public void setup(Context context)
throws IOException, InterruptedException {
//Nothing
} @Override
public void reduce(Text key, Iterable<IntWritable> values,
Context context) throws IOException, InterruptedException {
//TODO
} @Override
public void cleanup(
Context context)
throws IOException, InterruptedException {
//Nothing
} } // step3: Driver, component job
public int run(String[] args) throws Exception {
// 1: get confifuration
Configuration configuration = getConf(); // 2: create job
Job job = Job.getInstance(configuration, this.getClass()
.getSimpleName()); // run jar
job.setJarByClass(this.getClass()); // 3: set job
// input->map->reduce->output
// 3.1: input
Path inPath = new Path(args[0]);
FileInputFormat.addInputPath(job, inPath); // 3.2 map
job.setMapperClass(ModuleMapper.class);
//TODO
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class); //*****************shuffle********************
// 1) partitioner
//job.setPartitionerClass(cls); // 2)sort
//job.setSortComparatorClass(cls); // 3) optional, combiner
//job.setCombinerClass(cls); // 4) group
//job.setGroupingComparatorClass(cls); //*****************shuffle********************
// 3.3: reduce
job.setReducerClass(ModuleReducer.class);
//TODO
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class); // 3.4:output
Path outPath = new Path(args[1]);
FileOutputFormat.setOutputPath(job, outPath); // 4:
boolean isSuccess = job.waitForCompletion(true); return isSuccess ? 0 : 1 ;
} //step 4: run program
public static void main(String[] args) throws Exception {
// 1: get confifuration
Configuration configuration = new Configuration(); //set compress; 启用压缩
configuration.set("mapreduce.map.output.compress", "true");
//压缩格式
configuration.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec"); //int status = new WordCountMapReduce().run(args);
int status = ToolRunner.run(configuration, new ModuleMapReduce(), args); System.exit(status);
}
}
2.27 MapReduce Shuffle过程如何在Job中进行设置的更多相关文章
- MapReduce Shuffle过程
MapReduce Shuffle 过程详解 一.MapReduce Shuffle过程 1. Map Shuffle过程 2. Reduce Shuffle过程 二.Map Shuffle过程 1. ...
- 彻底理解MapReduce shuffle过程原理
彻底理解MapReduce shuffle过程原理 MapReduce的Shuffle过程介绍 Shuffle的本义是洗牌.混洗,把一组有一定规则的数据尽量转换成一组无规则的数据,越随机越好.MapR ...
- 【转】如何在vmware中如何设置ip
如何在vmware中如何设置ip 1.修改网络接口选hostonly2.虚拟机里安装vmware-tool,对鼠标和图形进行更好地支持.如果你在图形界面下,首先要切换到文本模式.右键点击桌面,打开一个 ...
- MapReduce:Shuffle过程的流程
Shuffle过程是MapReduce的核心,Shuffle描述着数据从map task输出到reduce task输入的这段过程. 1.map端
- MapReduce shuffle过程剖析及调优
MapReduce简介 在Hadoop MapReduce中,框架会确保reduce收到的输入数据是根据key排序过的.数据从Mapper输出到Reducer接收,是一个很复杂的过程,框架处理了所有问 ...
- MapReduce:详解Shuffle过程(转)
/** * author : 冶秀刚 * mail : dennyy99@gmail.com */ Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapRedu ...
- MapReduce:详解Shuffle过程
Shuffle过程,也称Copy阶段.reduce task从各个map task上远程拷贝一片数据,并针对某一片数据,如果其大小超过一定的阀值,则写到磁盘上,否则直接放到内存中. 官方的Shuffl ...
- MapReduce:详解Shuffle过程
Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapReduce, Shuffle是必须要了解的.我看过很多相关的资料,但每次看完都云里雾里的绕着,很难理清大致的逻辑, ...
- [转]MapReduce:详解Shuffle过程
Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapReduce, Shuffle是必须要了解的.我看过很多相关的资料,但每次看完都云里雾里的绕着,很难理清大致的逻辑, ...
随机推荐
- 单点登录CAS-Demo
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 1安全证书配置 2部署服务端CAS-Server 3部署CAS-Client 4测试SSO 1,安全证书配置 CAS默认 ...
- Android Studio 2.0 Beta 5公布,修复几个与即时执行相关的严重BUG.
Android Studio 2.0 Beta 5公布,修复几个与即时执行相关的严重BUG. This build fixes a couple of important bugs related t ...
- BUPT复试专题—求导数(2015)
题目描述 描述:求函数f(x) = a*x^3 + b*x^2 + c*x + d在x = x0处的一阶导数. 输入 数据第一行是数据的组数m 接下来m行的每一行分别是 a b c d x0 输出 ...
- CentOS下常用的 19 条命令
玩过Linux的人都会知道,Linux中的命令的确是非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
- python requests接收chunked编码问题-python源码修改
python requests接收chunked编码问题-python源码修改 学习了:https://blog.csdn.net/wangzuxi/article/details/40377467
- javascript 在线文本编辑器
javascript 在线文本编辑器实现代码. 效果例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcGhwZmVuZ2h1bw==/font/5 ...
- ios9定位服务的app进入后台三分钟收不到经纬度,应用被挂起问题及解决方式
原来定位服务是10分钟收不到定位信息就挂起定位,如今变为最短3分钟,预计都是为了省电吧. 仅仅要你开启应用的后台定位,而且10分钟有一次定位,那么苹果就不会关闭你的线程.如今变成3分钟.若你的应用开启 ...
- VC中常见API函数使用方法(经验版)
***********************************************声明*************************************************** ...
- 横跨十年CPU架构回顾
http://cpu.zol.com.cn/209/2092791_all.html#p2092791 本文导航 第1页:K7架构 打开AMD崛起大门的钥匙 第2页:玩破解 K7时代便已经拥有 第3页 ...
- Eureka vs Zookeeper
著名的CAP理论指出,一个分布式系统不可能同时满足C(一致性).A(可用性)和P(分区容错性).由于分区容错性在是分布式系统中必须要保证的,因此我们只能在A和C之间进行权衡.在此Zookeeper保证 ...