2016-12-21  16:53:49

mapred-default.xml

mapreduce.input.fileinputformat.split.minsize 0

The minimum size chunk that map input should be split into.

Note that some file formats may have minimum split sizes that take priority over this setting.

2016-12-11  18:56:44

JSON解析

1、根据JSON对象key的结构,创建对应的Java类;

2、通过反序列化,获取JSON对象key的值;

//反序列化
/*
[{
"value": "1",
"key": "a"
}, {
"value": "2",
"key": "b"
}]
*/
String propsStr = "[{\"value\":\"1\",\"key\":\"a\"},{\"value\":\"2\",\"key\":\"b\"}]";
List<PropsObject> propsList = JSON.parseArray(propsStr, PropsObject.class); /*
[{
"action_name": "begin",
"current_time": 1481221047146
}, {
"action_name": "end",
"current_time": 1481221058263,
"props": [{
"value": "1",
"key": "a"
}, {
"value": "2",
"key": "b"
}]
}]
*/
String actionsStr = "[{\"action_name\":\"begin\",\"current_time\":1481221047146},{\"action_name\":\"end\",\"current_time\":1481221058263,\"props\":[{\"value\":\"1\",\"key\":\"a\"},{\"value\":\"2\",\"key\":\"b\"}]}]";
List<ActionsObject> actionsList = JSON.parseArray(actionsStr, ActionsObject.class);
public class PropsObject {
private String key;
private String value;
//...
}
import java.util.List;

public class ActionsObject {
private String action_name;
private String current_time;
private List<PropsObject> props;
//...
}

2016-11-15  16:37:05

需要多少个Map?

Map的数目通常是由输入数据的大小决定的,一般就是所有输入文件的总块(block)数。

Map正常的并行规模大致是每个节点(node)大约10到100个map,对于CPU 消耗较小的map任务可以设到300个左右。由于每个任务初始化需要一定的时间,因此,比较合理的情况是map执行的时间至少超过1分钟。

这样,如果你输入10TB的数据,每个块(block)的大小是128MB(conf.setLong("mapreduce.input.fileinputformat.split.maxsize", 134217728L);),你将需要大约82,000个map来完成任务。

需要多少个Reduce?

Reduce的数目建议是0.95或1.75乘以 (<no. of nodes> * mapred.tasktracker.reduce.tasks.maximum)。

用0.95,所有reduce可以在maps一完成时就立刻启动,开始传输map的输出结果。用1.75,速度快的节点可以在完成第一轮reduce任务后,可以开始第二轮,这样可以得到比较好的负载均衡的效果。

增加reduce的数目会增加整个框架的开销,但可以改善负载均衡,降低由于执行失败带来的负面影响。

上述比例因子比整体数目稍小一些是为了给框架中的推测性任务(speculative-tasks) 或失败的任务预留一些reduce的资源。

无Reducer

如果没有归约要进行,那么设置reduce任务的数目为是合法的。

这种情况下,map任务的输出会直接被写入由 setOutputPath(Path)指定的输出路径。框架在把它们写入FileSystem之前没有对它们进行排序。

20161020

1、RCFile文件数据解析乱码

1.0、代码

Text columnText = new Text();

BytesRefWritable brw = cols.get(3);

columnText.set(brw.getData(), brw.getStart(), brw.getLength());

String columnValue = columnText.toString();

1.1、原因

解析字段的数据类型为int,转为String后出现乱码;

1.2、解决

提前将字段的数据类型由int转为string,如:cast(columnName as string) as columnName。

20161021

1、DistributedCache

1.1、将文件加入DistributedCache

通过命令行-files:将指定的hdfs文件分发到各个Task的工作目录下,不对文件进行任何处理;

Applications can specify a comma separated list of paths which would be present in the current working directory of the task using the option -files.
1.2、问题
使用时出现hive目录下文件(如:hdfs:///user/hive/warehouse/db_name.db/tb_name/file_name)无法加入DistributedCache的问题,
改为其他hdfs文件(如:hdfs:///dir_name1/dir_name2/file_name)后可以加入DistributedCache。

DISTRIBUTED_CACHE_FILE=hdfs:///dirname/filename

hadoop jar ${SHELL_DIR}/${JAR_NAME}.jar ${MAIN_CLASS} \
-files ${DISTRIBUTED_CACHE_FILE}

2016-10-20  16:52:09

hadoop -libjars

The -libjars option allows applications to add jars to the classpaths of the maps and reduces.

HIVE_LIB=${HIVE_HOME}/lib
HCATALOG_LIB=${HIVE_HOME}/hcatalog/share/hcatalog export HADOOP_CLASSPATH=${HIVE_LIB}/*:${HCATALOG_LIB}/*:${HADOOP_CLASSPATH} LIB_JARS=""
for j in `ls -1 ${HIVE_LIB}/*.jar`
do
LIB_JARS=${LIB_JARS},$j
done
for j in `ls -1 ${HCATALOG_LIB}/*.jar`
do
LIB_JARS=${LIB_JARS},$j
done
LIB_JARS=${LIB_JARS:1} hadoop jar ${SHELL_DIR}/${JAR_NAME}.jar ${MAIN_CLASS} \
-libjars ${LIB_JARS}

2016-10-20  17:23:40

MapReduce Tutorial

http://hadoop.apache.org/docs/r2.7.3/hadoop-mapreduce-client/hadoop-mapreduce-client-core/MapReduceTutorial.html

Input and Output types of a MapReduce job:

(input) <k1, v1> -> map -> <k2, v2> -> combine -> <k2, v2> -> reduce -> <k3, v3> (output)

The key and value classes have to be serializable by the framework and hence need to implement the Writable interface.

Additionally, the key classes have to implement the WritableComparable interface to facilitate sorting by the framework.

WritableComparables can be compared to each other, typically via Comparators.

All intermediate values associated with a given output key are subsequently grouped by the framework, and passed to the Reducer(s) to determine the final output.

Users can control the grouping by specifying a Comparator via Job.setGroupingComparatorClass(Class).

The Mapper outputs are sorted and then partitioned per Reducer. The total number of partitions is the same as the number of reduce tasks for the job.

Users can control which keys (and hence records) go to which Reducer by implementing a custom Partitioner.

The MapReduce framework relies on the InputFormat of the job to:

  1. Validate the input-specification of the job.

  2. Split-up the input file(s) into logical InputSplit instances, each of which is then assigned to an individual Mapper.

  3. Provide the RecordReader implementation used to glean input records from the logical InputSplit for processing by the Mapper.

The MapReduce framework relies on the OutputFormat of the job to:

  1. Validate the output-specification of the job; for example, check that the output directory doesn’t already exist.

  2. Provide the RecordWriter implementation used to write the output files of the job. Output files are stored in a FileSystem.

You can use CombineFileInputFormat for when the input has many small files.

If a maxSplitSize is specified, then blocks on the same node are combined to form a single split.

CombineFileRecordReader

A generic RecordReader that can hand out different recordReaders for each chunk in a CombineFileSplit.

A CombineFileSplit can combine data chunks from multiple files.

This class allows using different RecordReaders for processing these data chunks from different files.

GenericWritable

A wrapper for Writable instances.

When two sequence files, which have same Key type but different Value types, are mapped out to reduce, multiple Value types is not allowed. In this case, this class can help you wrap instances with different types.

MapReduce的更多相关文章

  1. Mapreduce的文件和hbase共同输入

    Mapreduce的文件和hbase共同输入 package duogemap;   import java.io.IOException;   import org.apache.hadoop.co ...

  2. mapreduce多文件输出的两方法

    mapreduce多文件输出的两方法   package duogemap;   import java.io.IOException;   import org.apache.hadoop.conf ...

  3. mapreduce中一个map多个输入路径

    package duogemap; import java.io.IOException; import java.util.ArrayList; import java.util.List; imp ...

  4. Hadoop 中利用 mapreduce 读写 mysql 数据

    Hadoop 中利用 mapreduce 读写 mysql 数据   有时候我们在项目中会遇到输入结果集很大,但是输出结果很小,比如一些 pv.uv 数据,然后为了实时查询的需求,或者一些 OLAP ...

  5. [Hadoop in Action] 第5章 高阶MapReduce

    链接多个MapReduce作业 执行多个数据集的联结 生成Bloom filter   1.链接MapReduce作业   [顺序链接MapReduce作业]   mapreduce-1 | mapr ...

  6. 使用mapreduce计算环比的实例

    最近做了一个小的mapreduce程序,主要目的是计算环比值最高的前5名,本来打算使用spark计算,可是本人目前spark还只是简单看了下,因此就先改用mapreduce计算了,今天和大家分享下这个 ...

  7. MapReduce剖析笔记之八: Map输出数据的处理类MapOutputBuffer分析

    在上一节我们分析了Child子进程启动,处理Map.Reduce任务的主要过程,但对于一些细节没有分析,这一节主要对MapOutputBuffer这个关键类进行分析. MapOutputBuffer顾 ...

  8. MapReduce剖析笔记之七:Child子进程处理Map和Reduce任务的主要流程

    在上一节我们分析了TaskTracker如何对JobTracker分配过来的任务进行初始化,并创建各类JVM启动所需的信息,最终创建JVM的整个过程,本节我们继续来看,JVM启动后,执行的是Child ...

  9. MapReduce剖析笔记之六:TaskTracker初始化任务并启动JVM过程

    在上面一节我们分析了JobTracker调用JobQueueTaskScheduler进行任务分配,JobQueueTaskScheduler又调用JobInProgress按照一定顺序查找任务的流程 ...

随机推荐

  1. Android性能优化之利用LeakCanary检测内存泄漏及解决办法

    前言: 最近公司C轮融资成功了,移动团队准备扩大一下,需要招聘Android开发工程师,陆陆续续面试了几位Android应聘者,面试过程中聊到性能优化中如何避免内存泄漏问题时,很少有人全面的回答上来. ...

  2. 神马玩意,EntityFramework Core 1.1又更新了?走,赶紧去围观

    前言 哦,不搞SQL了么,当然会继续,周末会继续更新,估计写完还得几十篇,但是我会坚持把SQL更新完毕,绝不会烂尾,后续很长一段时间没更新的话,不要想我,那说明我是学习新的技能去了,那就是学习英语,本 ...

  3. ecshop验证码

    <?php //仿制ecshop验证码(四位大写字母和数字.背景) //处理码值(四位大写字母和数字组成) //所有的可能的字符集合 $chars = 'ABCDEFGHIJKLMNOPQRST ...

  4. Mysql - 性能优化之子查询

    记得在做项目的时候, 听到过一句话, 尽量不要使用子查询, 那么这一篇就来看一下, 这句话是否是正确的. 那在这之前, 需要介绍一些概念性东西和mysql对语句的大致处理. 当Mysql Server ...

  5. linux练习题

    观察系统当前进程的运行情况的命令是( ):A.freeB.dmesgC.topD.last 答案:http://hovertree.com/tiku/bjag/foxg5n0q.htm Linux系统 ...

  6. jetBrain系列软件

    请尽量支持正版软件!https://www.jetbrains.com/ 本文仅供参考 以下提供一种方法可以无限期体验JetBrain2016系列软件. 1.下载JetbrainsCrack-2.5. ...

  7. 简易nginx TCP反向代理设置

    nginx从1.9.0开始支持TCP反向代理,之前只支持HTTP.这是我的系统示意图: 为何需要? 为什么需要反向代理?主要是: 负载均衡 方便管控 比如我现在要更新后端服务器,如果不用负载均衡的话, ...

  8. 浅谈跨域以及WebService对跨域的支持

    跨域问题来源于JavaScript的同源策略,即只有 协议+主机名+端口号 (如存在)相同,则允许相互访问.也就是说JavaScript只能访问和操作自己域下的资源,不能访问和操作其他域下的资源. 在 ...

  9. EasyPR--开发详解(8)文字定位

    今天我们来介绍车牌定位中的一种新方法--文字定位方法(MSER),包括其主要设计思想与实现.接着我们会介绍一下EasyPR v1.5-beta版本中带来的几项改动. 一. 文字定位法 在EasyPR前 ...

  10. stanford corenlp自定义切词类

    stanford corenlp的中文切词有时不尽如意,那我们就需要实现一个自定义切词类,来完全满足我们的私人定制(加各种词典干预).上篇文章<IKAnalyzer>介绍了IKAnalyz ...