ContainerLaunchContext.setResource() missing of hadoop yarn



http://hadoop.apache.org/docs/r2.1.0-beta/hadoop-yarn/hadoop-yarn-site/WritingYarnApplications.html

我试图从上面的链接使示例运行良好,但我无法编译下面的代码

 Resource capability = Records.newRecord(Resource.class);
 capability.setMemory(512);
 amContainer.setResource(capability);
 // Set the container launch content into the
 // ApplicationSubmissionContext
 appContext.setAMContainerSpec(amContainer);

amContainer 是 ContainerLaunchContext,我的 hadoop 版本是 2.1.0-beta。我做了一些调查。我发现在ContainerLaunchContext中没有方法"setResource"

我有3个问题
1)方法已被删除还是什么?
2)如果该方法已被删除,我现在该怎么办?
3)有没有关于纱线的文档,因为我发现网站上的文档很容易,我希望我能得到一本手册什么的。例如能力设置内存(512);我不知道根据代码中的注释是 512k 还是 512M。

这实际上是对问题的适当解决方案。以前的答案可能会导致不正确的执行!!

@Dyin 我无法将其放入评论;)已针对 2.2.0 和 2.3.0 进行验证

驱动程序为 AppMaster 设置资源:

ApplicationSubmissionContext appContext = app.getApplicationSubmissionContext();
ApplicationId appId = appContext.getApplicationId();
appContext.setApplicationName(this.appName);
// Set up the container launch context for the application master
ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
Resource capability = Records.newRecord(Resource.class);
capability.setMemory(amMemory);        
appContext.setResource(capability);
appContext.setAMContainerSpec(amContainer);
Priority pri = Records.newRecord(Priority.class);
pri.setPriority(amPriority);
appContext.setPriority(pri);
appContext.setQueue(amQueue);
// Submit the application to the applications manager
yarnClient.submitApplication(appContext); // this.yarnClient = YarnClient.createYarnClient();

在 ApplicationMaster 中,您应该如何为容器(工作线程)指定资源。

private AMRMClient.ContainerRequest setupContainerAskForRM() {
        // setup requirements for hosts
        // using * as any host will do for the distributed shell app
        // set the priority for the request
        Priority pri = Records.newRecord(Priority.class);
        pri.setPriority(requestPriority);
        // Set up resource type requirements
        // For now, only memory is supported so we set memory requirements
        Resource capability = Records.newRecord(Resource.class);
        capability.setMemory(containerMemory);
        AMRMClient.ContainerRequest request = new AMRMClient.ContainerRequest(capability, null, null,
                pri);
        return request;
    }

AppMaster 中的一些 run() 或 main() 方法

AMRMClientAsync.CallbackHandler allocListener = new RMCallbackHandler();
resourceManager = AMRMClientAsync.createAMRMClientAsync(1000, allocListener);
resourceManager.init(conf);
resourceManager.start();
for (int i = 0; i < numTotalContainers; ++i) {
  AMRMClient.ContainerRequest containerAsk = setupContainerAskForRM();
  resourceManager.addContainerRequest(containerAsk); // 
}

启动容器您可以使用原始答案解决方案(java cmd),但它只是顶部的樱桃。无论如何,它应该有效。

您可以通过推荐设置可用于 ApplicationMaster 的内存。因此:

// Set the necessary command to execute the application master
Vector<CharSequence> vargs = new Vector<CharSequence>(30);
...
vargs.add("-Xmx" + amMemory + "m"); // notice "m" indicating megabytes, you can use also -Xms combined with -Xmx
... // transform vargs to String commands
amContainer.setCommands(commands);

这应该可以解决您的问题。至于3个问题。纱线是快速发展的软件。我的建议忘记文档,获取源代码并阅读它。这将回答您的很多问题。

相关内容

  • 没有找到相关文章