《Hadoop权威指南》书摘-MapReduce概述

转载请注明出处
独立博客:http://wangnan.tech
简书:http://www.jianshu.com/u/244399b1d776**
知乎:https://zhuanlan.zhihu.com/c_121958856

MapReduce是一种可用于数据处理的编程模型,MapReduce程序本质上是并行运行的,因此可以将大规模数据分析任务分发给任何一个拥有足够多机器的数据中心,它的优势在于处理大规模数据

map和reduce

MapReduce任务可以分为两个处理阶段:map阶段和reduce阶段,每个阶段都以键值对作为输入和输出

一些概念

job
MapReduce job 是客户端需要执行的一个工作单元,它包括输入数据,MapReduce程序和配置信息

task
Hadoop将 job 分成若干 task 执行,task包括两类:map任务和reduce任务,这些任务运行在集群的节点上,并通过YARN进行调度,如果任务失败,它将在另一个不同的节点上自动重新调度运行

split
hadoop将MapReduce的输入数据划分成等长的小数据块,成为split,hadoop为每个分片创建一个map任务

对于大多数作业来说,一个合理的分片大小趋向于HDFS的一个块的大小,默认是123MB

数据本地化优化
Hadoop在储存有输入数据(HDFS中的数据)的节点上运行map任务,可以获得最佳性能,因为它无需使用宝贵的集群带宽资源,但是有时储存该分片的hdfs数据块副本所在的节点可能在运行其他的map任务,此时调度需要从某一个数据块所在的机架中的一个节点上寻找一个空闲的map槽(slot)来运行该map任务分片,仅仅在非常偶然的情况下会发生,这将导致机架之间发生网络传输

思考题:为什么最近分片大小应该与块大小相同

思考题:为什么map任务将其输出写入本地磁盘,而不是HDFS

reduce

reduce任务并不具备数据本地化优势,单个reduce任务的输入通常来自于所有mapper的输出,reduce的输出通常储存在HDFS中以实现可靠储存,reduce输出的每个HDFS块,第一个副本储存在本地节点上,其他复本出于可靠性考虑储存在其他机架的节点上

reduce数据流图

reduce任务的数量并非由输入数据的大小决定,相反是独立的

partition
如果有好多个reduce任务,每个map任务就会针对输出进行分区(partition),即为每个reduce任务建一个分区,每个分区有许多键,但每个建对应的键值对记录都在同一个分区中,分区可以由用户定义的分区函数控制,但通常默认的partitioner通过哈希函数来分区,很高效


shuffle
多个reduce任务的数据流如图,map和reduce任务之间的数据流成为shuffle(混洗),因为每个reduce任务的输入都来自许多map任务,shuffle一般比图中所示的更负责,而且调整shuffle参数对作业总执行时间影响比较大

当数据完全可以并行,无需shuffle时,可能出现无reduce任务的情况,这种情况下,唯一的非本地节点数据传输是map任务

combiner函数
能帮助减少mapper和reducer之间的数据传输量

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这本书很全,是Hadoop中的圣经级教材,不过看起来挺累。 内容简介 Discover how Apache Hadoop can unleash the power of your data. This comprehensive resource shows you how to build and maintain reliable, scalable, distributed systems with the Hadoop framework -- an open source implementation of MapReduce, the algorithm on which Google built its empire. Programmers will find details for analyzing datasets of any size, and administrators will learn how to set up and run Hadoop clusters. This revised edition covers recent changes to Hadoop, including new features such as Hive, Sqoop, and Avro. It also provides illuminating case studies that illustrate how Hadoop is used to solve specific problems. Looking to get the most out of your data? This is your book. Use the Hadoop Distributed File System (HDFS) for storing large datasets, then run distributed computations over those datasets with MapReduce Become familiar with Hadoop’s data and I/O building blocks for compression, data integrity, serialization, and persistence Discover common pitfalls and advanced features for writing real-world MapReduce programs Design, build, and administer a dedicated Hadoop cluster, or run Hadoop in the cloud Use Pig, a high-level query language for large-scale data processing Analyze datasets with Hive, Hadoop’s data warehousing system Take advantage of HBase, Hadoop’s database for structured and semi-structured data Learn ZooKeeper, a toolkit of coordination primitives for building distributed systems "Now you have the opportunity to learn about Hadoop from a master -- not only of the technology, but also of common sense and plain talk."

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值