Detailed MapReduce

Please reprint from the source: http://eksliang.iteye.com/blog/2228705

1. Composition of MapReduce in Hadoop 1.0

1. From the perspective of functional modules
  • Client : submit MapReduce jobs;
  • Job Tracker :

1. Job scheduling: divide a job (Job) into several sub-tasks and distribute them to taskTraker for execution

2. Task monitoring: TaskTracker sends a heartbeat to JobTracker to report its running status, so that JobTracker can monitor him

3. Resource management: each task applies for resources to the JobTracker

4. During the monitoring process, if a task that fails or runs too slowly is found, restart it

  • TaskTraker:

Actively send a heartbeat to the jobTracker and communicate with the JobTracker, so as to receive the tasks sent by the JobTracker to be executed

2. From an architectural perspective
  1. Programming model (new and old API)
  2.  Operating environment (JobTracker and TaksTracker)
  3.  Data processing engine (MapTask and ReduceTask)

 

2. Resource management model of MapReduce (hadoop1.0)

2.1 The resource composition of MapReduce consists of two parts
  • Resource Representation Model

Used to describe the representation of resources, Hadoop 1.0 uses "slots" to organize the resources of each node. In order to simplify the management of resources, Hadoop puts resources (CPU, memory, network IO, disk IO, etc.) on each node, etc. The amount is divided into several parts, each part is represented by "slot", and it is stipulated that a task can occupy multiple "slots" according to the actual situation.

Simply put: Hadoop 1.0 abstracts multi-dimensional resources and uses "slot" to represent them, thereby simplifying the management of resources.

  • Resource Allocation Model

The resource allocation model determines how to allocate resources to various jobs/tasks. In Hadoop, this part is done by a pluggable scheduler.

更进一步说,slot相当于运行的“许可证”,一个任务只有获得“许可证”后,才能够获得运行的机会,这也意味着,每一个节点上的slot的数量决定了当前节点能够并发执行多少个任务。Hadoop1.0为了区分MapTask跟ReduceTask所使用资源的差异,进一步将slot分为MapSlot跟ReduceSlot,他们分别只能被MapTask跟ReduceTask使用。

 

Hadoop集群管理员可根据各个节点硬件配置和应用特点为它们分配不同的map slot数(由参数mapred.tasktracker.map.tasks.maximum指定)和reduce slot数(由参数mapred.tasktrackerreduce.tasks.maximum指定)

 

2.2Hadoop1.0资源管理的缺点
  1. 静态资源配置。采用了静态资源设置策略,即每个节点事先配置好可用的slot总数,这些slot数目一旦启动后无法再动态修改。
  2. 资源无法共享。Hadoop 1.0将slot分为Map slot和Reduce slot两种,且不允许共享。对于一个作业,刚开始运行时,Map slot资源紧缺而Reduce slot空闲,当Map Task全部运行完成后,Reduce slot紧缺而Map slot空闲。很明显,这种区分slot类别的资源管理方案在一定程度上降低了slot的利用率。
  3. 资源划分粒度过大。资源划分粒度过大,往往会造成节点资源利用率过高或者过低 ,比如,管理员事先规划好一个slot代表2GB内存和1个CPU,如果一个应用程序的任务只需要1GB内存,则会产生“资源碎片”,从而降低集群资源的利用率,同样,如果一个应用程序的任务需要3GB内存,则会隐式地抢占其他任务的资源,从而产生资源抢占现象,可能导致集群利用率过高。
  4. 没引入有效的资源隔离机制。Hadoop 1.0仅采用了基于jvm的资源隔离机制,这种方式仍过于粗糙,很多资源,比如CPU,无法进行隔离,这会造成同一个节点上的任务之间干扰严重。

三.Year的资源管理模型

      在实际系统中,资源本身是多维度的,包括CPU、内存、网络I/O和磁盘I/O等,因此,如果想精确控制资源分配,不能再有slot的概念,最直接的方法就是是让任务直接向调度器申请自己需要的资源(比如某个任务可申请1GB 内存和1个CPU),而调度器则按照任务实际需求为其精细地分配对应的资源量,不再简单的将一个Slot分配给它,Hadoop 2.0正式采用了这种基于真实资源量的资源分配方案。

       MRv2最基本的设计思想是将JobTracker的两个主要功能,即资源管理和作业调度/监控分成两个独立的进程。全局的ResourceManager(RM)和与每个应用相关的ApplicationMaster(AM)。

“RM有两个组件组成:调度器(Scheduler)应用管理器(ApplicationsManager,ASM)”

如下图是官网提供的year架构图



 

3.1 Year的功能组成模块

       调度器是个可插拔的组件,负责作业的调度并将集群中的资源分配给应用。YARN自带了多个资源调度器,如Capacity Scheduler和Fair Scheduler等。

       ASM:负责接收任务,并指定AS运行的节点NM节点,同时启动AM

 

  • NM:是每个节点上的资源管理,负责处理来自RM的命令,处理AM的命令,主动发送心跳给RM,让RM能够监控NM的运行状态。
  • AM:就是我们的应用(应用可以是mapduce程序或者DAG有向无环图)
  • Container:是YARN中资源的抽象,将操作系统中多维度的资源(CPU、内存、网络I/O和磁盘I/O等)封装成container,是Year中资源的基本单位
3.2 应用在Year中的运行流程
  1. 客户端提交一个应用程序AM到ResourceManager上
  2. ResourceManager先与集群中NodeManager通信,根据集群中NodeManger的资源   使用情况,确定运行AM的NodeManager;
  3. 确定了运行的节点后,AM马上向RM申请资源,资源被封装成Container的形式响应给AM,申请到资源后和确定了执行的NM后,RM马上在NM上启动AM
  4. 所有任务运行完成后,ApplicationMaster向ResourceManager注销,整个应用程序运行结束。

 

四.MapReduce1与MapRreduce2的区别

      如果从MapReduce的功能模块去区分他们,会比较乱,很难直观的说清楚,如果从MapReduce的系统架构入手,这个问题就变得简单了

MapReduce1从架构的角度可以分为三个部分

  1. 编程模型(新旧API)
  2. 运行环境(JobTracker和TaskTracker)
  3. 数据处理引擎(MapTask和ReduceTask)

MapReduce2从架构的角度可以分为三个部分

  1. 编程模型(新旧API)
  2. 运行环境(Year)
  3. 数据处理引擎(MapTask和ReduceTask)

从架构可以很清楚区分到,他们之间的区别主要在运行环境变了!

 

参考博客:

Shuffle和排序:http://langyu.iteye.com/blog/992916

董的博客Mapreduce的资源分配:http://dongxicheng.org/mapreduce-nextgen/hadoop-yarn-configurations-resourcemanager-nodemanager/

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326358318&siteId=291194637