在传统的MapReduce中, Jobtracker同时负责作业调度(将任务调度给对应的tasktracker)和任务进度管理(监控任务, 重启失败的或者速度比较慢的任务等). YARN中将Jobtracker的责任划分给两个独立的守护进程: 资源管理器(resource manager)负责管理集群的所有资源,
在传统的MapReduce中, Jobtracker同时负责作业调度(将任务调度给对应的tasktracker)和任务进度管理(监控任务, 重启失败的或者速度比较慢的任务等). YARN中将Jobtracker的责任划分给两个独立的守护进程: 资源管理器(resource manager)负责管理集群的所有资源, 应用管理器(application master)负责管理集群上任务的生命周期. 具体的做法是应用管理器向资源管理器提出资源需求, 以container为单位, 然后在这些container中运行该应用相关的进程. container由运行在集群节点上的节点管理器监控, 确保应用不会用超资源. 每个应用的实例, 亦即一个MapReduce作业都有一个自己的应用管理器.
综上所述, YARN中包括以下几个角色
- 客户端, 向整个集群提交MapReduce作业
- YARN资源管理器, 负责调度整个集群的计算资源
- YARN节点管理器, 在集群的机器上启动以及监控container
- MapReduce应用管理器, 调度某个作业的所有任务. 应用管理器和任务运行在container中, container由资源管理器调度, 由节点管理器管理.
- 分布式文件系统, 通常是HDFS.
YARN中运行一个作业的流程如下图所示:

1. 作业提交
YARN中的提交作业的API和经典的MapReduce很像(第1步). 作业提交的过程和经典的MapReduce很像, 新的作业ID(应用ID)由资源管理器分配(第2步). 作业的客户端核实作业的输出, 计算输入的split, 将作业的资源(包括Jar包, 配置文件, split信息)拷贝给HDFS(第3步). 最后, 通过调用资源管理器的submitApplication()来提交作业(第4步).
2. 作业初始化
当资源管理器收到submitApplciation()的请求时, 就将该请求发给调度器(scheduler), 调度器分配container, 然后资源管理器在该container内启动应用管理器进程, 由节点管理器监控(第5a和5b步).
MapReduce作业的应用管理器是一个主类为MRAppMaster的Java应用. 其通过创造一些bookkeeping对象来监控作业的进度, 得到任务的进度和完成报告(第6步). 然后其通过分布式文件系统得到由客户端计算好的输入split(第7步). 然后为每个输入split创建一个map任务, 根据mapreduce.job.reduces创建reduce任务对象.
然后应用管理器决定如何运行构成整个作业的任务. 如果作业很小, 应用管理器会选择在其自己的JVM中运行任务, 这种作业称作是被unerized, 或者是以uber task的方式运行. 在任务运行之前, 作业的setup方法被调用来创建输出路径. 与MapRuduce 1中该方法由tasktracker运行的一个任务调用不同, 在YARN中是由应用管理器调用的.
3. 任务分配
如果不是小作业, 那么应用管理器向资源管理器请求container来运行所有的map和reduce任务(第8步). 这些请求是通过心跳来传输的, 包括每个map任务的数据位置, 比如存放输入split的主机名和机架(rack). 调度器利用这些信息来调度任务, 尽量将任务分配给存储数据的节点, 或者退而分配给和存放输入split的节点相同机架的节点.
请求也包括了任务的内存需求, 默认情况下map和reduce任务的内存需求都是1024MB. 可以通过mapreduce.map.memory.mb和mapreduce.reduce.memory.mb来配置.
分配内存的方式和MapReduce 1中不一样, MapReduce 1中每个tasktracker有固定数量的slot, slot是在集群配置是设置的, 每个任务运行在一个slot中, 每个slot都有最大内存限制, 这也是整个集群固定的. 这种方式很不灵活.
在YARN中, 资源划分的粒度更细. 应用的内存需求可以介于最小内存和最大内存之间, 并且必须是最小内存的倍数.
4. 任务运行
当一个任务由资源管理器的调度器分配给一个container后, 应用管理器通过练习节点管理器来启动container(第9a步和9b步). 任务有一个主类为YarnChild的Java应用执行. 在运行任务之前首先本地化任务需要的资源, 比如作业配置, JAR文件, 以及分布式缓存的所有文件(第10步). 最后, 运行map或reduce任务(第11步).
YarnChild运行在一个专用的JVM中, 但是YARN不支持JVM重用.
5. 进度和状态更新
YARN中的任务将其进度和状态(包括counter)返回给应用管理器, 后者通过每3秒的脐带接口有整个作业的视图(view). 这和MapRduce 1不太一样, 后者的进度流从tasktracker到jobtracker. 下图为MapReduce 2中的进度更新流:

客户端每秒(通过mapreduce.client.progressmonitor.pollinterval设置)向应用管理器请求进度更新, 展示给用户.
在MapReduce 1中, jobtracker的UI有运行的任务列表及其对应的进度. 在YARN中, 资源管理器的UI展示了所有的应用以及各自的应用管理器的UI.
6. 作业完成
除了向应用管理器请求作业进度外, 客户端每5分钟都会通过调用waitForCompletion()来检查作业是否完成. 时间间隔可以通过mapreduce.client.completion.pollinterval来设置.
作业完成之后, 应用管理器和container会清理工作状态, OutputCommiter的作业清理方法也会被调用. 作业的信息会被作业历史服务器存储以备之后用户核查.
参考文献:
[1]. Hadoop: The Definitive Guide. 3rd Edition. Chapter 6, YARN.
485 total views, no views today
原文地址:YARN作业运行机制, 感谢原作者分享。

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor