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是必须要了解的.我看过很多相关的资料,但每次看完都云里雾里的绕着,很难理清大致的逻辑, ...
随机推荐
- 统计显著性(Statistical significance)
显著性,又称统计显著性(Statistical significance), 是指零假设为真的情况下拒绝零假设所要承担的风险水平,又叫概率水平,或者显著水平. [1] 显著性的含义是指两个群体的态度之 ...
- 【转】Spring框架深入理解
参考这篇文章: http://www.ibm.com/developerworks/cn/java/j-lo-spring-principle/ Spring内部分为Beans, Context 和 ...
- weex 项目开发(六)weexpack 项目 打包、签名、发布
一. weexpack build android 和 weexpack run android 的 区别. (1)单纯打包 weexpack build android (2)打包并运行 wee ...
- 互斥锁和条件变量(pthread)相关函数
互斥锁 #include <pthread.h> // 若成功返回0,出错返回正的Exxx值 // mptr通常被初始化为PTHREAD_MUTEX_INITIALIZER int pth ...
- Spring Boot与Micronaut性能比较
文章转载出处:微信公众号——锅外的大佬 链接:https://mp.weixin.qq.com/s/MdBByJ0ju-rROKg7jsWygA 今天我们将比较两个在JVM上构建微服务的框架:Spri ...
- 一个简单的EBNF范式的实现
最近无事在看书的时候发现了这个东西刹那间突然觉得大学时候编译原理书上的的什么语法分析书.上下文无关等晦涩难懂的概念清晰了许多今天把它贴出来希望也能让你回想起些往事... 至于EBNF范式是什么东西,网 ...
- 单字节的FIFO缓存(30天自制操作系统--读书笔记)
从今天起,写一些读书笔记.最近几个月都在看<30天自制操作系统这本书>,书虽说看的是电子书,但可以花钱买的正版书,既然花费了金钱,就总得有些收获. 任何人都不能总是固步自封,想要进步就得学 ...
- c语言基本函数
1. 用宏定义写出swap(x,y) #define swap(x, y) x = x + y; y = x - y; x = x - y; 2.数组a[N],存放了1至N-1个数,其中某个数重复一次 ...
- 2款JS脚本判断手机浏览器跳转WAP手机网站
随着移动设备的普及,企业的网络宣传已经不能局限在PC端,而需要同时在移动端有所建树.对于公司网站来说,以前都是做的PC端的,当然手机等移动端也可以访问,但是用户体验肯定不如完全适合的手机端来的方便.我 ...
- 简单的JDBC编程步骤
1.加载数据库驱动(com.mysql.jdbc.Driver) 2.创建并获取数据库链接(Connection) 3.创建jdbc statement对象(PreparedStatement) 4. ...