Seven, yarn basic principles

[TOC]

A, Hadoop1.x difference between architecture and Hadoop2.x

In Hadoop1.x in, MapReduce scheduling and business logic operation, the degree of coupling itself is responsible for a large resource, and even then only support a MapReduce framework.
In Hadoop2.x, increasing the yarn, responsible for resource scheduling, the MapReduce only responsible for the business logic operation, and operation on the yarn may be other distributed computing frameworks as spark like.

Two, yarn basic architecture

Seven, yarn basic principles

2.1 yarn basic structure of FIG.

Divided into RM (ResourceManager), NM (NodeManager), AM (ApplicationMaster).

1, the relevant Glossary

Resources:

在 YARN 的语境下,资源特指计算资源,包括 CPU 和内存。计算机的每个进程都会占用一定的 CPU 和内存,任务需要先向 RM 申请到资源后才能获准在 NM 上启动自己的进程。

queue:

YARN 将整个集群的资源划分为队列,每个用户的任务必须提交到指定队列。同时限制每个队列的大小,防止某个用户的任务占用整个集群,影响了其他用户的使用。

vcore、Mem:

逻辑 CPU 和逻辑内存,每个 NM 会向 RM 汇报自己有多少 vcore 和内存可用,具体数值由集群管理员配置。比如一台48核,128G内存的机器,可以配置40vcore,120G内存,意为可以对外提供这么多资源。具体数值可能根据实际情况有所调整。每个 NM 的逻辑资源加起来,就是整个集群的总资源量。

MinResources & MaxResources:

为了使每个队列都能得到一定的资源,同时又不浪费集群的空闲资源,队列的资源设置都是“弹性”的。每个队列都有 min 和 max 两个资源值,min 表示只要需求能达到,集群一定会提供这么多资源;如果资源需求超过了 min 值而同时集群仍有空闲资源,则仍然可以满足;但又限制了资源不能无限申请以免影响其他任务,资源的分配不会超过 max 值。这里是指整个队列获得的资源总数

container:

任务申请到资源后在 NM 上启动的进程统称 Container。比如在 MapReduce 中可以是 Mapper 或 Reducer,在 Spark 中可以是 Driver 或 Executor。

RM(ResourceManager),NM(NodeManager)、AM(ApplicationMaster):

ResourceManager(rm):
处理客户端请求、启动/监控ApplicationMaster、监控NodeManager、资源分配与调度

NodeManager(nm):
单个节点上的资源管理、处理来自ResourceManager的命令、处理来自ApplicationMaster的命令

ApplicationMaster:
数据切分、为应用程序申请资源,并分配给内部任务、任务监控与容错。其实就是MapReduce任务的driver端程序运行的地方。用于任务的调度。前面的RM和NM都是用于资源调度

2, yarn working mechanism Overview

1) using the client user to submit a job to the task RM, specify which queue and the amount of resources required to submit to. The user can set the corresponding parameters calculated for each engine, if not specified, the default setting.

2) RM upon request submitted tasks, in accordance with whether the resource to satisfy the selection request queue and a NM, it starts a special notification Container, referred ApplicationMaster (AM), which is initiated by the subsequent procedure. Each task has only one AM.

3) After registering the AM RM own tasks as needed, apply to RM container, including the number of factors the amount of resources, location and other needs.

4) If the queue has sufficient resources, RM will be assigned to the container has enough resources remaining NM, NM start notification by the AM container.

5) to perform specific tasks start after container processing division to its own data. In addition NM responsible for starting the container, it is also responsible for monitoring its resource usage and whether the failure to exit the work, if the container specified memory than the actual use of application memory, it will kill other container to ensure normal operation.

6) report to the AM each container at their own pace, after the completion of all, AM and exit to the cancellation of the task RM, RM notice NM killed corresponding container, End Task.

Three, yarn working mechanism

Seven, yarn basic principles

Figure 3.1 yarn mechanism

(0)Mr程序提交到客户端所在的节点。
(1)Yarnrunner向Resourcemanager申请一个Application
(2)RM将该应用程序的资源路径返回给yarnrunner。
(3)该程序将运行所需资源提交到HDFS上,放到hdfs指定目录下,如上图所示,资源主要有3部分,一是所有切片信息的规划文件,二是job的一个运行配置文件(包含job的一些运行参数等),三是MapReduce程序的jar包了
(4)程序资源提交完毕后,申请运行mrAppMaster。
(5)RM将用户的请求初始化成一个task。
(6)其中一个NodeManager领取到task任务。
(7)该NodeManager创建容器Container,并产生MRAppmaster。
(8)Container从HDFS上拷贝资源到本地。
(9)MRAppmaster向RM 申请运行maptask资源。
(10)RM将运行maptask任务分配给另外两个NodeManager,另两个NodeManager分别领取任务并创建容器
(11)MR向两个接收到任务的NodeManager发送程序启动脚本,这两个NodeManager分别启动maptask,maptask对数据分区排序。
(12)MrAppMaster等待所有maptask运行完毕后,向RM申请容器,运行reduce task。
(13)reduce task向maptask获取相应分区的数据。
(14)程序运行完毕后,appMaster会向RM申请注销自己。

四、yarn资源作业调度器

yarn会为任务分配资源,这个过程中涉及到资源的调度,目前yarn支持的资源调度器有三种:FIFO、capacity scheduler、fair scheduler。目前默认的是 capacity scheduler

1、设置使用哪个资源调度器

//yarn-default.xml
<property>
    <description>The class to use as the resource scheduler.</description>
    <name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>
</property>

2、FIFO

Seven, yarn basic principles

​ 图4.1 FIFO调度器

优点:调度算法简单,JobTracker(job提交任务后发送得地方)工作负担轻。

缺点:忽略了不同作业的需求差异。例如如果类似对海量数据进行统计分析的作业长期占据计算资源,那么在其后提交的交互型作业有可能迟迟得不到处理,从而影响到用户的体验。

3、capacity scheduler -- yahoo开发

Seven, yarn basic principles

​ 图 4.2 capacity scheduler调度器

1.多队列支持,每个队列采用FIFO
2.为了防止同一个用户的作业独占队列中的资源,该调度器会对同一个用户提交多的作业所占资源量进行限定
3.首先,计算每个队列中正在运行的任务数与其应该分得的计算资源(队列中已有任务总共应该分的资源的总和)之间的比值,选择一个该比值最小的队列
4.其次,根据作业的优先级和提交时间顺序,同时考虑用户资源量限制和内存限制对队列内任务排序
5.三个队列同时按照任务的先后顺序依次执行,比如,job1,job21和job31分别排在队列最前面,是最先运行,也是同时运行

该调度默认情况下不支持优先级,但是可以在配置文件中开启此选项,如果支持优先级,调度算法就是带有优先级的FIFO。
不支持优先级抢占,一旦一个作业开始执行,在执行完之前它的资源不会被高优先级作业所抢占。
对队列中同一用户提交的作业能够获得的资源百分比进行了限制以使同属于一用户的作业不能出现独占资源的情况。即同一用户在不同队列所能使用的资源的百分比

4、fair scheduler--Facebook开发

Seven, yarn basic principles

​ 图 4.3 fair scheduler调度器

1.支持多队列多用户,每个队列中的资源量可以配置,同一个队列中的作业公平共享队列中所有资源

2.比如有三个队列A,B,C.每个队列中的job按照优先级分配资源,优先级越高分配的资源越多,但是每个job都分配到资源以确保公平。在资源有限的情况下,每个job理想情况下,获得的计算资源与实际获得的计算资源存在一种差距,这个差距叫做缺额。同一个队列,job的资源缺额越大,越先获得的资源优先执行,作业是按照缺额的高低来先后执行的,而且可以看到上图有多个作业同时运行

五、任务的推测执行

1、推测执行的定义

推测执行(Speculative Execution)是指在集群环境下运行MapReduce,可能是程序Bug,负载不均或者其他的一些问题,导致在一个JOB下的多个TASK速度不一致,比如有的任务已经完成,但是有些任务可能只跑了10%,根据木桶原理,这些任务将成为整个JOB的短板,如果集群启动了推测执行,这时为了最大限度的提高短板,Hadoop会为该task启动备份任务,让speculative task与原始task同时处理一份数据,哪个先运行完,则将谁的结果作为最终结果,并且在运行完成后Kill掉另外一个任务。

2、推测运行的机制

发现拖后腿的任务,比如某个任务运行速度远慢于任务平均速度。为拖后腿任务启动一个备份任务,同时运行。谁先运行完,则采用谁的结果。并且运行完之后,会将未执行完成的任务直接kill掉。

3、推测运行任务的前提

1) Each task can have only one backup task;
2) current job has been completed task must not be less than 5%;
3) the case of speculative execution can not be enabled: there is a serious load tilt between tasks; special tasks, such as task to the database writing data;
4) open speculative execution parameters, mapred-site.xml default is open

开启map任务的推测执行
<property>
  <name>mapreduce.map.speculative</name>
  <value>true</value>
  <description>If true, then multiple instances of some map tasks                may be executed in parallel.</description>
</property>

开启reduce任务的推测执行
<property>
  <name>mapreduce.reduce.speculative</name>
  <value>true</value>
  <description>If true, then multiple instances of some reduce tasks 
               may be executed in parallel.</description>
</property>

Guess you like

Origin blog.51cto.com/kinglab/2445046