hadoop源码_Apache Hadoop YARN:Client<>ResourceManager源码DEBUG

点击关注上方“知了小巷”,

设为“置顶或星标”,第一时间送达干货。

本文将通过DEBUG的方式进行源码跟踪,

探查YARN客户端与ResourceManager之间简单的交互过程,

以yarnClient.getAllQueues()获取YARN集群所有队列信息为例进行演示

Hadoop版本3.2.1

DEBUG环境:IntelliJ IDEA

一、 测试用例

这里直接调用YarnClient的静态方法createYarnClient()

创建一个YarnClient实例new YarnClientImpl();。

yarnClient.init(conf)初始化主要是设置配置参数(处理配置文件)和通知监听器(服务状态变更),其中初始化会调用serviceInit(config)【详见YarnClientImpl中具体实现】。

yarnClient.start()首先判断如果已经处于已启动状态则直接返回,否则给stateChangeLock加上synchronized锁,然后调用serviceStart()

【详见YarnClientImpl中具体实现,在serviceStart方法中首先会去初始化rmClient,过程涉及多个Proxy和Handler,

底层会用到Java的

java.lang.reflect.Proxy#newProxyInstance;

另外重点:初始化rmClient的过程中,

在RMProxy#newProxyInstance方法中有这样两行行代码

T proxy = instance.getProxy(conf, protocol, rmAddress);return (T) RetryProxy.create(protocol, proxy, retryPolicy);

会去初始化ApplicationClientProtocolPBClientImpl对象并返回,所以从

Apache Hadoop YARN:ClientResourceManager源码解析

的调用关系图中也可发现rmClient就是ApplicationClientProtocolPBClientImpl对象。

】。

yarnClient.getAllQueues()从ResourceManager获取YARN集群所有队列信息,从此处DEBUG下去。

ApplicationClientProtocolPBServiceImpl见名知意,这是ResourceManager服务端实现的。

package yarn.client.test;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.yarn.api.records.QueueInfo;import org.apache.hadoop.yarn.client.api.YarnClient;import org.junit.Test;import java.util.List;public class MyTestYarnClient {    @Test    public void testYarnClientVisitRM() throws Exception {        YarnClient yarnClient = YarnClient.createYarnClient();        Configuration conf = new Configuration();        yarnClient.init(conf);        yarnClient.start();        List queueInfos = yarnClient.getAllQueues();        System.out.println(queueInfos);    }}

二、 首先启动ResourceManager

配置ResourceManager启动设置

b58fe333fd1fc638b0dd582832b5f9a3.png

启动ResourceManager

4b9152bdd0a734335c8ba77a72c8fd39.png

三、 打上断点,DEBUG模式运行MyTestYarnClient#testYarnClientVisitRM

c86af97bfe104881305d1b95f99d6837.png

四、 DEBUG下一步跟踪YarnClientImpl#getAllQueues

60d4478f8e3b3e24cf0846165112f267.png

五、 DEBUG下一步跟踪到RetryInvocationHandler#invoke

71e14b5d2b377e5a942317745c8af253.png

六、 DEBUG下一步ApplicationClientProtocolPBClientImpl#getQueueInfo

cb60c62c603285a24a77693d15a9ee7e.png

七、 下一步ApplicationClientProtocolPBServiceImpl#getQueueInfo

正式进入ResourceManager

67b8eb91c7a3d69e47f19f18e02b081a.png

八、 最后一步ClientRMService#getQueueInfo

86de16a731d6fc3de7a62d269e04eced.png

九、 END 打印YARN集群队列信息

[queueName: "default" capacity: 1.0 maximumCapacity: 1.0 currentCapacity: 0.0 state: Q_RUNNING accessibleNodeLabels: "*" queueStatistics { numAppsSubmitted: 0 numAppsRunning: 0 numAppsPending: 0 numAppsCompleted: 0 numAppsKilled: 0 numAppsFailed: 0 numActiveUsers: 0 availableMemoryMB: 0 allocatedMemoryMB: 0 pendingMemoryMB: 0 reservedMemoryMB: 0 availableVCores: 0 allocatedVCores: 0 pendingVCores: 0 reservedVCores: 0 allocatedContainers: 0 pendingContainers: 0 reservedContainers: 0 } preemptionDisabled: true queueConfigurationsMap { partitionName: "" queueConfigurations { capacity: 1.0 absoluteCapacity: 1.0 maxCapacity: 1.0 absoluteMaxCapacity: 1.0 maxAMPercentage: 0.1 effectiveMinCapacity { memory: 0 virtual_cores: 0 resource_value_map { key: "memory-mb" value: 0 units: "Mi" type: COUNTABLE } resource_value_map { key: "vcores" value: 0 units: "" type: COUNTABLE } } effectiveMaxCapacity { memory: 0 virtual_cores: 0 resource_value_map { key: "memory-mb" value: 0 units: "Mi" type: COUNTABLE } resource_value_map { key: "vcores" value: 0 units: "" type: COUNTABLE } } } } intraQueuePreemptionDisabled: true]Disconnected from the target VM, address: '127.0.0.1:63224', transport: 'socket'

1747d7f3c70ec02ac003724a1f322cf6.png

【END】

往期推荐:

Apache Hadoop YARN:ClientResourceManager源码解析

Hive企业级调优

HiveQL查询连续三天有销售记录的店铺

HiveQL实战蚂蚁森林低碳用户排名分析:解法一

HiveQL实战蚂蚁森林低碳用户排名分析:解法二

HiveQL实战蚂蚁森林植物申领统计分析

Hive-函数

Hive-查询

Hive-DML(Data Manipulation Language)数据操作语言

Hive-DDL(Data Definition Language)数据定义

Hive优化(整理版)

Spark Core之Shuffle解析

数据仓库开发规范

7d78872ed9d30c32cd438e8804c4a1a3.png 

2a03eb6fa0d46032efcd012fb64b1131.gif

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值