gpt4 book ai didi

hadoop - ContainerLaunchContext.setResource() 缺少 hadoop yarn

转载 作者:可可西里 更新时间:2023-11-01 15:39:30 30 4
gpt4 key购买 nike

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)有没有关于yarn的文档,因为我发现网站上的文档很简单,我希望我能得到一份手册之类的。例如,能力.setMemory(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 中,这是您应该如何为容器( worker )指定资源。

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),但这只是锦上添花。它应该无论如何都可以工作。

关于hadoop - ContainerLaunchContext.setResource() 缺少 hadoop yarn,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18944678/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com