【问题标题】:How to set the memory for a yarn application's container different from application master如何为不同于应用程序主控的纱线应用程序的容器设置内存
【发布时间】:2017-03-03 06:22:07
【问题描述】:

我有一个应用程序主机和一个基于代码from the Hadoop documentation 的纱线客户端。目前,yarn 客户端使用与应用程序主服务器相同的内存配置,但我想提供允许用户为应用程序最终运行的容器指定内存需求的功能。

我一直在查看 YarnClient 和 ApplicationSubmissionContext 的 Java 文档,但我仍然对是否可以仅为应用程序的容器设置内存和 vcore 感到困惑。

YarnClient 有代码:

// Set up the container launch context for the application master
ContainerLaunchContext amContainer = ContainerLaunchContext.newInstance(
                    localResources, env, commands, null, null, null);

// Set up resource type requirements
// For now, both memory and vcores are supported, so we set memory and
// vcores requirements
Resource capability = Resource.newInstance(amMemory, amVCores);
appContext.setResource(capability);

JavaDocs 声明setResource 设置了ApplicationMaster 为此应用程序所需的资源。我认为这意味着我只能在创建 ApplicationSubmissionContext 时为 ApplicationMaster 配置容器。那是对的吗?

如何为将在 YarnClient 中运行应用程序的容器指定 vcore 和内存?

编辑

我看到YarnClient中也设置了以下内容。这导致更多的问题。资源是否设置了两次?还是代码的一部分设置了应用程序的容器,另一部分设置了应用程序主的容器?

// Set java executable command
LOG.info("Setting up app master command");
vargs.add(Environment.JAVA_HOME.$$() + "/bin/java");
// Set Xmx based on am memory size
vargs.add("-Xmx" + amMemory + "m");
// Set class name
vargs.add(appMasterMainClass);
// Set params for Application Master
vargs.add("--container_memory " + String.valueOf(containerMemory));
vargs.add("--container_vcores " + String.valueOf(containerVirtualCores));
vargs.add("--num_containers " + String.valueOf(numContainers));
vargs.add("--priority " + String.valueOf(shellCmdPriority));

【问题讨论】:

    标签: hadoop hadoop-yarn


    【解决方案1】:

    我进行了一些测试,结果发现问题中提到的两段代码中,以下代码将设置 Application Master 从命令行提取的值,以便为应用程序构建 YARN 容器:

    // Set java executable command
    LOG.info("Setting up app master command");
    vargs.add(Environment.JAVA_HOME.$$() + "/bin/java");
    // Set Xmx based on am memory size
    vargs.add("-Xmx" + amMemory + "m");
    // Set class name
    vargs.add(appMasterMainClass);
    // Set params for Application Master
    vargs.add("--container_memory " + String.valueOf(containerMemory));
    vargs.add("--container_vcores " + String.valueOf(containerVirtualCores));
    vargs.add("--num_containers " + String.valueOf(numContainers));
    vargs.add("--priority " + String.valueOf(shellCmdPriority));
    

    Application Master 中获取这些值的代码是:

        //getOptionValue(char opt, String defaultValue)
        containerMemory = Integer.parseInt(cliParser.getOptionValue(
            "container_memory", "1024"));
        containerVirtualCores = Integer.parseInt(cliParser.getOptionValue(
            "container_vcores", "1"));
        numTotalContainers = Integer.parseInt(cliParser.getOptionValue(
            "num_containers", "1"));
        if (numTotalContainers == 0) {
          throw new IllegalArgumentException(
              "Cannot run analytic with no containers");
        }
        requestPriority = Integer.parseInt(cliParser
            .getOptionValue("priority", "0"));
    

    【讨论】:

      猜你喜欢
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 2015-11-02
      • 2020-09-17
      • 2013-07-08
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      相关资源
      最近更新 更多