【原创】大叔经验分享(21)yarn中查看每个应用实时占用的内存和cpu资源

摘要:
纱线应用详情页http://resourcemanager/cluster/app/$applicationId或通过应用程序命令yarnappapplication status$applicationId,您只能看到自应用程序启动以来占用的资源*时间统计信息,例如:AggregateResourceAllocation:3962853MB秒,1466vc

在yarn中的application详情页面

http://resourcemanager/cluster/app/$applicationId

或者通过application命令

yarn application -status $applicationId

只能看到应用启动以来占用的资源*时间统计,比如:

Aggregate Resource Allocation : 3962853 MB-seconds, 1466 vcore-seconds

到处都找不到这个应用当前实时的资源占用情况,比如当前占用了多少内存多少核,跟进yarn代码发现其实是有这个统计的:

org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport

  public static ApplicationResourceUsageReport newInstance(
      int numUsedContainers, int numReservedContainers, Resource usedResources,
      Resource reservedResources, Resource neededResources, long memorySeconds,
      long vcoreSeconds) {
    ApplicationResourceUsageReport report =
        Records.newRecord(ApplicationResourceUsageReport.class);
    report.setNumUsedContainers(numUsedContainers);
    report.setNumReservedContainers(numReservedContainers);
    report.setUsedResources(usedResources);
    report.setReservedResources(reservedResources);
    report.setNeededResources(neededResources);
    report.setMemorySeconds(memorySeconds);
    report.setVcoreSeconds(vcoreSeconds);
    return report;
  }

其中usedResources就是当前的实时占用资源情况,包括内存和cpu,这个统计是在YarnScheduler的接口中返回:

org.apache.hadoop.yarn.server.resourcemanager.scheduler.YarnScheduler

  /**
   * Get a resource usage report from a given app attempt ID.
   * @param appAttemptId the id of the application attempt
   * @return resource usage report for this given attempt
   */
  @LimitedPrivate("yarn")
  @Evolving
  ApplicationResourceUsageReport getAppResourceUsageReport(
      ApplicationAttemptId appAttemptId);

getAppResourceUsageReport方法被RMAppAttemptImpl.getApplicationResourceUsageReport调用:

org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttemptImpl

  @Override
  public ApplicationResourceUsageReport getApplicationResourceUsageReport() {
    this.readLock.lock();
    try {
      ApplicationResourceUsageReport report =
          scheduler.getAppResourceUsageReport(this.getAppAttemptId());
      if (report == null) {
        report = RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT;
      }
      AggregateAppResourceUsage resUsage =
          this.attemptMetrics.getAggregateAppResourceUsage();
      report.setMemorySeconds(resUsage.getMemorySeconds());
      report.setVcoreSeconds(resUsage.getVcoreSeconds());
      return report;
    } finally {
      this.readLock.unlock();
    }
  }

RMAppAttemptImpl.getApplicationResourceUsageReport被两个地方调用:

第一个调用

org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMAppImpl

  public ApplicationReport createAndGetApplicationReport(String clientUserName,
      boolean allowAccess) {
...
          appUsageReport = currentAttempt.getApplicationResourceUsageReport();
...

RMAppImpl.createAndGetApplicationReport会被ClientRMService.getApplications和ClientRMService.getApplicationReport调用,这两个方法分别对应命令

yarn application -list
yarn application -status $applicationId

这两个地方展示信息的时候都没展示usedResources,可能作者觉得这个实时资源占用统计没那么重要。

详见:
org.apache.hadoop.yarn.server.resourcemanager.ClientRMService

第二个调用

org.apache.hadoop.yarn.server.resourcemanager.webapp.dao.AppInfo

  public AppInfo(RMApp app, Boolean hasAccess, String schemePrefix) {
...
          ApplicationResourceUsageReport resourceReport = attempt
              .getApplicationResourceUsageReport();
          if (resourceReport != null) {
            Resource usedResources = resourceReport.getUsedResources();
            allocatedMB = usedResources.getMemory();
            allocatedVCores = usedResources.getVirtualCores();
            runningContainers = resourceReport.getNumUsedContainers();
          }
...

这个构造函数会在RMWebServices.getApp和RMWebServices.getApps时被调用,这是个service接口,对应url分别为:

http://resourcemanager/ws/v1/cluster/apps/$applicationId
http://resourcemanager/ws/v1/cluster/apps?state=RUNNING

这两个接口的返回值中有实时资源占用情况如下:

<allocatedMB>56320</allocatedMB>
<allocatedVCores>21</allocatedVCores>

分别对应实时内存占用和实时CPU占用;

详见:
org.apache.hadoop.yarn.server.resourcemanager.webapp.RMWebServices

如果你发现spark应用内存的占用比你分配的要多,可以参考这里:https://www.cnblogs.com/barneywill/p/10102353.html

免责声明:文章转载自《【原创】大叔经验分享(21)yarn中查看每个应用实时占用的内存和cpu资源》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇UML类图关系(泛化 、继承、实现、依赖、关联、聚合、组合)中断上下文下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Switch离线升级教程【自用】

想写这篇博客的原因还是因为自己发现明明已经自己通过大佬指导以及论坛教程指导,自己实践两次过了完整流程后,仍会因为相隔太久的固件更新而遗忘到底如何离线升级。当然这也是自己写的第一篇对于自己实用性较高的生活小技巧。 首先根据论坛大神的精华贴,为什么要对switch进行离线升级。首先升级很好理解,因为新游戏需要更新的系统支持下才能运行。因此在原生系统破解之后不足...

报错记录:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

以下是错误信息: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): org.ml.apply.persistence.UserInfoMapper.login at org.apache.ibatis.binding.MapperMeth...

iOS -证书制作

iOS证书制作攻略及配置注意事项 使用APICloud平台开发APP商用,首先得有开发者账号和各种证书,之后云编译打包正式版,上传到appstore审核上架。现在APICloud特别推出,证书申请和配置在控制台配置证书的注意事项的攻略,提供给大家。 云编译p12证书制作 生成certSigningRequest文件 如图,打开应用程序->实用工具-&...

WMI_COM_API

Win32_Processor // CPU 处理器   Win32_PhysicalMemory // 物理内存   Win32_Keyboard // 键盘   Win32_PointingDevice // 点输入设备,如鼠标   Win32_DiskDrive // 硬盘驱动器   Win32_CDROMDrive // 光盘驱动器   Win32...

微信开发笔记:获取用户openid,以及用户头像昵称等信息

微信开发的时候有一个很便利的途径来进行一个用户的一步注册登录,就是使用用户的微信信息来直接进行登陆,可以省去很多不必要的麻烦。那具体这些信息是如何来获取的呢? 首先呢,我们需要对微信进行一个授权,让微信页面有权限来读取我们的用户信息: $redirect_uri = urlencode($url); //设置授权页面,此处填写回调的授权页面地址 $scop...

SQL Server与Oracle有什么区别?

1.可操作平台上: Oracle可在所有主流平台上运行,Oracle数据库采用开放的策略目标,它使得客户可以选择一种最适合他们特定需要的解决方案。客户可以利用很多种第三方应用程序、工具。而SQL Server却只能在Windows上运行了。 但SQL Sever在Window平台上的表现,和Windows操作系统的整体结合程度,使用方便性,和Microso...