一、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中进行设置的更多相关文章

  1. MapReduce Shuffle过程

    MapReduce Shuffle 过程详解 一.MapReduce Shuffle过程 1. Map Shuffle过程 2. Reduce Shuffle过程 二.Map Shuffle过程 1. ...

  2. 彻底理解MapReduce shuffle过程原理

    彻底理解MapReduce shuffle过程原理 MapReduce的Shuffle过程介绍 Shuffle的本义是洗牌.混洗,把一组有一定规则的数据尽量转换成一组无规则的数据,越随机越好.MapR ...

  3. 【转】如何在vmware中如何设置ip

    如何在vmware中如何设置ip 1.修改网络接口选hostonly2.虚拟机里安装vmware-tool,对鼠标和图形进行更好地支持.如果你在图形界面下,首先要切换到文本模式.右键点击桌面,打开一个 ...

  4. MapReduce:Shuffle过程的流程

    Shuffle过程是MapReduce的核心,Shuffle描述着数据从map task输出到reduce task输入的这段过程. 1.map端

  5. MapReduce shuffle过程剖析及调优

    MapReduce简介 在Hadoop MapReduce中,框架会确保reduce收到的输入数据是根据key排序过的.数据从Mapper输出到Reducer接收,是一个很复杂的过程,框架处理了所有问 ...

  6. MapReduce:详解Shuffle过程(转)

    /** * author : 冶秀刚 * mail     : dennyy99@gmail.com */ Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapRedu ...

  7. MapReduce:详解Shuffle过程

    Shuffle过程,也称Copy阶段.reduce task从各个map task上远程拷贝一片数据,并针对某一片数据,如果其大小超过一定的阀值,则写到磁盘上,否则直接放到内存中. 官方的Shuffl ...

  8. MapReduce:详解Shuffle过程

    Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapReduce, Shuffle是必须要了解的.我看过很多相关的资料,但每次看完都云里雾里的绕着,很难理清大致的逻辑, ...

  9. [转]MapReduce:详解Shuffle过程

    Shuffle过程是MapReduce的核心,也被称为奇迹发生的地方.要想理解MapReduce, Shuffle是必须要了解的.我看过很多相关的资料,但每次看完都云里雾里的绕着,很难理清大致的逻辑, ...

随机推荐

  1. yum安装nginx详解

    原文:http://blog.csdn.net/tjcyjd/article/details/50686505 1.查看yum的nginx信息 # yum info nginx Loaded plug ...

  2. jobject和jclass

    jclass和jobject的迷惑第一次使用JNI,实例引用(jobject)和类引用(jclass)让人觉得很困惑.实例引用与一个数组和java.lang.Object类或它的子类的实例对应.类引用 ...

  3. 【Mongodb教程 第十八课 】MongoDB常用命令 数据库命令 集合操作命令

    面向文档的 NoSQL 数据库主要解决的问题不是高性能的并发读写,而是保证海量数据存储的同时,具有良好的查询性能.  条件操作符 <, <=, >, >=  这个操作符就不用多 ...

  4. MCE----Machine-check exception

    http://en.wikipedia.org/wiki/Machine_Check_Exception Machine-check exception From Wikipedia, the fre ...

  5. oracle SQL语句(转)

    Oracle数据库语句大全 ORACLE支持五种类型的完整性约束 NOT NULL (非空)--防止NULL值进入指定的列,在单列基础上定义,默认情况下,ORACLE允许在任何列中有NULL值. CH ...

  6. mysql的DUPLICATE KEY

    经常遇到这样的情景,向一个表里插入一条数据,如果已经存在就更新一下,用程序实现麻烦而且在并发的时候可能会有问题,这时用mysql的DUPLICATE KEY 很方便 用法如下: INSERT INTO ...

  7. Array types are now written with the brackets around the element type问题的解决方法

    在xcode6.1中来编写swift空数组时.出现的的这个问题,依照官方 Swift 教程<The Swift Programming Language>来写 let emptyArray ...

  8. extjs4 treepanel 多个checkbox先中 多个节点选中 多级节点展开

    //<%@ page contentType="text/html; charset=utf-8" %> var checkedNodes = { _data:{}, ...

  9. iOS中UIPickerView常见属性和方法的总结

    UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...

  10. react native 之页面布局

     第一章 flexbox 布局 1.flexDirection:'row', 水平 flexDirection:'column',垂直 需要在父元素上设置这种属性才能实现flex. flex:1 会撑 ...