Hadoop版本2的引入改变了MapReduce应用程序在集群上的运行方式。与Hadoop版本1中的MapReduce-Schedule不同,Hadoop YARN已经推广了用户可用的集群资源。为了保持与Hadoop版本1的兼容性,YARN团队编写了一个在YARN之上运行的MapReduce框架。该框架与Hadoop版本1高度兼容, 与Hadoop版本1一样,Hadoop YARN提供了几乎相同的MapReduce示例和基准,可帮助演示Hadoop YARN的功能。
内容
运行Hadoop YARN MapReduce示例
运行现有的MapReduce示例是一个简单的过程。这些例子位于hadoop- [VERSION] / share / hadoop / mapreduce。根据您安装Hadoop的位置,此路径可能会有所不同。为了这个例子的目的,请参考如下路径:
export YARN_EXAMPLES = $ YARN_HOME / share / hadoop / mapreduce
应该将$ YARN_HOME定义为安装的一部分。此外,本节中给出的示例具有版本标签 – 在本例中为“2.7.0”。您的安装可能具有不同的版本标签。以下讨论提供了基于Hadoop YARN的MapReduce程序和一些示例。
列出可用的示例
bash-4.1# ./yarn jar ../share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar An example program must be given as the first argument. Valid program names are: aggregatewordcount: An Aggregate based map/reduce program that counts the words in the input files. aggregatewordhist: An Aggregate based map/reduce program that computes the histogram of the words in the input files. bbp: A map/reduce program that uses Bailey-Borwein-Plouffe to compute exact digits of Pi. dbcount: An example job that count the pageview counts from a database. distbbp: A map/reduce program that uses a BBP-type formula to compute exact bits of Pi. grep: A map/reduce program that counts the matches of a regex in the input. join: A job that effects a join over sorted, equally partitioned datasets multifilewc: A job that counts words from several files. pentomino: A map/reduce tile laying program to find solutions to pentomino problems. pi: A map/reduce program that estimates Pi using a quasi-Monte Carlo method. randomtextwriter: A map/reduce program that writes 10GB of random textual data per node. randomwriter: A map/reduce program that writes 10GB of random data per node. secondarysort: An example defining a secondary sort to the reduce. sort: A map/reduce program that sorts the data written by the random writer. sudoku: A sudoku solver. teragen: Generate data for the terasort terasort: Run the terasort teravalidate: Checking results of terasort wordcount: A map/reduce program that counts the words in the input files. wordmean: A map/reduce program that counts the average length of the words in the input files. wordmedian: A map/reduce program that counts the median length of the words in the input files. wordstandarddeviation: A map/reduce program that counts the standard deviation of the length of the words in the input files.
为了说明Hadoop YARN的多个功能,我们将演示如何运行pi例子。
运行Pi示例
要使用16个map和100,000个样本运行pi示例,请输入以下内容:
bash-4.1# ./yarn jar ../share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar pi 16 100000
如果程序正常运行,您应该看到以下内容(在日志消息之后):
bash-4.1# ./yarn jar ../share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.0.jar pi 16 100000 Number of Maps = 16 Samples per Map = 100000 Wrote input for Map #0 Wrote input for Map #1 Wrote input for Map #2 Wrote input for Map #3 Wrote input for Map #4 Wrote input for Map #5 Wrote input for Map #6 Wrote input for Map #7 Wrote input for Map #8 Wrote input for Map #9 Wrote input for Map #10 Wrote input for Map #11 Wrote input for Map #12 Wrote input for Map #13 Wrote input for Map #14 Wrote input for Map #15 Starting Job 18/05/27 09:04:56 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032 18/05/27 09:04:57 INFO input.FileInputFormat: Total input paths to process : 16 18/05/27 09:04:57 INFO mapreduce.JobSubmitter: number of splits:16 18/05/27 09:04:57 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1525140884470_0001 18/05/27 09:04:58 INFO impl.YarnClientImpl: Submitted application application_1525140884470_0001 18/05/27 09:04:58 INFO mapreduce.Job: The url to track the job: http://c55ef24f0fc0:8088/proxy/application_1525140884470_0001/ 18/05/27 09:04:58 INFO mapreduce.Job: Running job: job_1525140884470_0001 18/05/27 09:05:06 INFO mapreduce.Job: Job job_1525140884470_0001 running in uber mode : false 18/05/27 09:05:06 INFO mapreduce.Job: map 0% reduce 0% 18/05/27 09:05:19 INFO mapreduce.Job: map 38% reduce 0% 18/05/27 09:05:29 INFO mapreduce.Job: map 75% reduce 0% 18/05/27 09:05:38 INFO mapreduce.Job: map 100% reduce 0% 18/05/27 09:05:39 INFO mapreduce.Job: map 100% reduce 100% 18/05/27 09:05:40 INFO mapreduce.Job: Job job_1525140884470_0001 completed successfully 18/05/27 09:05:41 INFO mapreduce.Job: Counters: 49 File System Counters FILE: Number of bytes read=358 FILE: Number of bytes written=1963543 FILE: Number of read operations=0 FILE: Number of large read operations=0 FILE: Number of write operations=0 HDFS: Number of bytes read=4278 HDFS: Number of bytes written=215 HDFS: Number of read operations=67 HDFS: Number of large read operations=0 HDFS: Number of write operations=3 Job Counters Launched map tasks=16 Launched reduce tasks=1 Data-local map tasks=16 Total time spent by all maps in occupied slots (ms)=146042 Total time spent by all reduces in occupied slots (ms)=7885 Total time spent by all map tasks (ms)=146042 Total time spent by all reduce tasks (ms)=7885 Total vcore-seconds taken by all map tasks=146042 Total vcore-seconds taken by all reduce tasks=7885 Total megabyte-seconds taken by all map tasks=149547008 Total megabyte-seconds taken by all reduce tasks=8074240 Map-Reduce Framework Map input records=16 Map output records=32 Map output bytes=288 Map output materialized bytes=448 Input split bytes=2390 Combine input records=0 Combine output records=0 Reduce input groups=2 Reduce shuffle bytes=448 Reduce input records=32 Reduce output records=0 Spilled Records=64 Shuffled Maps =16 Failed Shuffles=0 Merged Map outputs=16 GC time elapsed (ms)=459 CPU time spent (ms)=8250 Physical memory (bytes) snapshot=4041662464 Virtual memory (bytes) snapshot=12525998080 Total committed heap usage (bytes)=2990538752 Shuffle Errors BAD_ID=0 CONNECTION=0 IO_ERROR=0 WRONG_LENGTH=0 WRONG_MAP=0 WRONG_REDUCE=0 File Input Format Counters Bytes Read=1888 File Output Format Counters Bytes Written=97 Job Finished in 44.84 seconds Estimated value of Pi is 3.14157500000000000000
请注意,MapReduce进度与MapReduce版本1中的方式相同,但应用程序统计信息不同。 大部分统计数字都有注释。 需要注意的一个重要项目是YARN“Map-Reduce Framework”用于运行程序。 本章后面将进一步讨论该框架的使用,该框架旨在与Hadoop版本1兼容。
使用Web GUI监控示例
Hadoop YARN Web GUI与Hadoop版本1中的Web GUI不同。下面介绍如何使用Web GUI监视和查找有关YARN作业的信息。 下图显示了主要的YARN Web界面(http:// hostname:8088)。 对于这个例子,我们使用pi应用程序,它可以在您探索GUI之前快速运行并完成。 当研究GUI中的所有各种链接时,运行时间较长的应用程序(如terasort)可能会有所帮助。
Hadoop YARN正在运行的应用程序Web GUI的pi示例
如果查看Cluster Node表,您将看到一些新的信息。 首先,会注意到,而不是Hadoop版本1“Map/Reduce Task Capacity”,现在有关于正在运行的容器数量的信息。 如果YARN正在运行MapReduce作业,这些容器将用于map任务和reduce任务。 与Hadoop版本1不同,map和reduce的数量并不固定。 还有内存度量和链接到节点状态。 如果您单击节点链接,则可以获取节点活动的信息。 例如,下图是pi应用程序运行时节点活动的快照。 再次注意容器的数量,MapReduce框架将其用作map或reduce。
Hadoop YARN 节点信息
回到主应用程序/运行窗口,如果你点击application_138 …链接,将显示下图中的应用程序状态窗口。 此窗口提供与“正在运行的应用程序”窗口类似的信息,但仅限于所选作业。
PI示例的Hadoop YARN应用程序状态
可以查看 AM 运行容器的详细信息,如下图:
Hadoop YARN AM 容器信息
可以查看YARN 资源调度的详细信息,如下图:
Hadoop YARN 资源调度
如前所述,当我们 遍历RM Web 界面时,有几件事需要注意。 首先,由于YARN管理应用程序,所有来自YARN的输入都是指应用程序。 YARN没有关于实际应用的数据。 来自MapReduce作业的数据由MapReduce框架提供。
另一个值得注意的方面是map和reduce任务的动态特性。 这些被作为YARN容器执行,并且它们的编号将随着应用程序的运行而改变。 由于没有静态插槽,此功能可提供更好的集群利用率。
最后,可以探索网页中的其他链接(例如,HistoryServer)。 通过MapReduce框架,可以深入到单个map和Reduce。 如果启用日志,则可以查看每个map和reduce的单个日志。
MapReduce兼容性
MapReduce是Hadoop开发的最初用例。为了绘制万维网图并说明它随着时间如何变化,开发了MapReduce来处理作其数十亿个节点和数万亿个边缘。由于数据局部性,容错性和应用程序优先级的要求,将此技术移植到YARN框架使是一项复杂的工作。
为了提供数据局部性,MapReduce ApplicationMaster需要定位要处理的块,然后在这些块上请求容器。为了实现容错,需要处理失败map或reduce任务并在其他节点上再次请求它们的能力。容错与应用优先级紧密相关。
处理复杂的应用map和reduce任务优先级的逻辑必须嵌入到ApplicationMaster中。在map完成处理足够的数据之前,不需要启动闲置的reduce。
MapReduce ApplicationMaster
MapReduce ApplicationMaster是作为松耦合服务的组合来实现的。这些服务通过事件相互影响。每个组件都处理收到的事件,并将任何所需的事件发送到其他组件。这种设计保持了高度的并发性,没有或很少有同步需求。这些事件由中央派遣机制派遣。所有组件都向Dispatcher注册,并使用AppContext在不同组件之间共享此信息。
在Hadoop版本1中,JobTracker如何死亡将导致所有作业丢失,包括正在运行的和排队的作业。使用YARN,ApplicationMaster是一个MapReduce作业,作为JobTracker的等价物。 ApplicationMaster现在将运行在计算节点上,这可能会导致故障情况的增加。为了对抗MapReduce ApplicationMaster失败的威胁,YARN有能力重新启动ApplicationMaster指定的次数以及恢复已完成任务的能力 。以下设置可以启用YARN中的MapReduce恢复。
ApplicationMaster重新启动
要启用ApplicationMaster重新启动,请执行以下操作:
1.在yarn-site.xml中,您可以调整属性yarn.resourcemanager.am.max-retries。 默认值是2。
2.在mapred-site.xml中,您可以更直接地调整MapReduce ApplicationMaster应使用属性mapreduce.am.max-attempts重新启动的次数。 默认值是2。
启用恢复已完成的任务
要启用已完成任务的恢复,请查看mapred-site.xml文件。 属性yarn.app.mapreduce.am.job.recovery.enable可以恢复任务。 默认情况下,默认值是true;
JobHistory服务器
随着ApplicationMaster现在代替了JobTracker,所有MapReduce作业的历史记录都需要存放在一个集中位置。 JobHistory服务器通过托管这些已完成的作业指标和日志来帮助弥补临时ApplicationMaster留下的空白。 这个新的历史守护进程与YARN提供的服务无关,并且直接绑定到MapReduce应用程序框架。
计算节点的容量
如果需要进行新的容量计算。计算节点容量有如下重要参数;它们位于mapred-site.xml和yarn-site.xml文件中。
mapred-site.xml mapreduce.map.memory.mb mapreduce.reduce.memory.mb mapreduce.map.java.opts mapreduce.reduce.java.opts
Mapper或Reducer任务的jvm -Xmx的堆大小。请为使用的JVM Perm Gen和Native Libs留出空间。该值应该总是小于mapreduce。[map | reduce] .memory.mb。
yarn-site.xml yarn.scheduler.minimum-allocation-mb
YARN允许的最小容器
yarn.scheduler.maximum-allocation-mb
YARN允许的最大容器
yarn.nodemanager.resource.memory-mb
计算节点上容器的物理内存(RAM)数量。此值不是节点上的总RAM,这一点很重要,因为其他Hadoop服务也需要RAM。
yarn.nodemanager.vmem-pmem-ratio
允许每个容器的虚拟内存量。这通过以下公式计算:containerMemoryRequest * vmem-pmem-ratio。
请看如下的 YARN MapReduce 配置信息
更改 Shuffle Service
MapReduce shuffle功能在NodeManager中作为辅助服务实现。该服务在NodeManager地址空间中启动Netty Web服务器,并知道如何处理来自reduce任务的MapReduce特定的随机请求。 MapReduce ApplicationMaster指定shuffle服务的服务ID以及ApplicationMaster启动任何容器时可能需要的安全令牌。在返回响应中,NodeManager向ApplicationMaster提供运行shuffle服务的端口,然后将其传递给reduce任务。
Hadoop版本2还提供了加密shuffle的选项。通过加密的shuffle功能,可以使用具有可选客户端身份验证的HTTPS。
如果除了默认的mapreduce_shuffle服务之外还要设置一个辅助服务,那么您应该为yarn.nodemanager.aux-services属性添加一个新的服务,例如mapreduce_shufflex。 然后,定义相应类的属性必须是yarn.nodemanager.aux-services.mapreduce_shufflex.class。