1

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)有没有关于纱线的文档,因为我发现网站上的文档很容易,我希望我能得到一个手册或什么的。例如,capability.setMemory(512);根据代码中的注释,我不知道它是 512k 还是 512M。

4

2 回答 2

1

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

@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),但这只是顶部的樱桃。无论如何它应该工作。

于 2014-03-12T13:55:56.400 回答
0

您可以通过推荐设置 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个问题。Yarn 是快速发展的软件。我的建议是忘记文档,获取源代码并阅读它。这将回答你的很多问题。

于 2013-11-04T14:18:00.993 回答