当前位置:   article > 正文

Apache Hadoop YARN:Client客户端与ResourceManager源码DEBUG_org.apache.hadoop.yarn.client.api.imp.time

org.apache.hadoop.yarn.client.api.imp.time

本文将通过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方法中有这样两行行代码

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

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

Apache Hadoop YARN:Client<-->ResourceManager源码解析

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

】。

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

 

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

  1. package yarn.client.test;
  2. import org.apache.hadoop.conf.Configuration;
  3. import org.apache.hadoop.yarn.api.records.QueueInfo;
  4. import org.apache.hadoop.yarn.client.api.YarnClient;
  5. import org.junit.Test;
  6. import java.util.List;
  7. public class MyTestYarnClient {
  8. @Test
  9. public void testYarnClientVisitRM() throws Exception {
  10. YarnClient yarnClient = YarnClient.createYarnClient();
  11. Configuration conf = new Configuration();
  12. yarnClient.init(conf);
  13. yarnClient.start();
  14. List<QueueInfo> queueInfos = yarnClient.getAllQueues();
  15. System.out.println(queueInfos);
  16. }
  17. }

二、 首先启动ResourceManager

配置ResourceManager启动设置

启动ResourceManager

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

四、 DEBUG下一步跟踪到YarnClientImpl#getAllQueues

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

六、 DEBUG下一步ApplicationClientProtocolPBClientImpl#getQueueInfo

七、 下一步ApplicationClientProtocolPBServiceImpl#getQueueInfo

 

正式进入ResourceManager

八、 最后一步ClientRMService#getQueueInfo

 

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

  1. [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]
  2. Disconnected from the target VM, address: '127.0.0.1:63224', transport: 'socket'

 

更多第一时间内容,微信扫描下面二维码关注公众号

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/999658
推荐阅读
相关标签
  

闽ICP备14008679号