spring - 使用Spring Yarn时如何向容器分配资源?

标签 spring hadoop resources yarn

我正在通过gradle构建的[github] [1]上的Spring Yarn示例。而且我成功地在yarn上运行了custom-amservice示例。

但是我不知道如何为容器分配特殊资源。我尝试在我的 CustomAppmaster 上的类 StaticEventingAppmaster 中覆盖类ont上的 onContainerAllocated onContainerLaunched 方法,并分配资源,如下所示。

@Override
protected void onContainerAllocated(Container container) {
       //==allocate resource
        Resource resource = new ResourcePBImpl();
        resource.setMemory(1300);
        resource.setVirtualCores(7);
        container.setResource(resource);
        //====
        if (getMonitor() instanceof ContainerAware) {
                ((ContainerAware)getMonitor()).onContainer(Arrays.asList(container));
        }
        getLauncher().launchContainer(container, getCommands());
}
@Override
protected void onContainerLaunched(Container container) {
       //==allocate resource
        Resource resource = new ResourcePBImpl();
        resource.setMemory(1300);
        resource.setVirtualCores(7);
        container.setResource(resource);
        //====
        if (getMonitor() instanceof ContainerAware) {
                ((ContainerAware)getMonitor()).onContainer(Arrays.asList(container));
        }
}

并且在日志中似乎可行:
2014-12-30 20:06:35,524 DEBUG [AbstractPollingAllocator] - response has 1 new containers
2014-12-30 20:06:35,525 DEBUG [AbstractPollingAllocator] - new container: container_1419934738198_0004_01_000003

////  this line shows the memory is 1300 and cpu core is 7
2014-12-30 20:06:35,525 DEBUG [DefaultContainerMonitor] - Reporting container=Container: [ContainerId: container_1419934738198_0004_01_000003, NodeId: yarn-master1:57799, NodeHttpAddress: yarn-master1:8042, Resource: <memory:1300, vCores:7>, Priority: 0, Token: Token { kind: ContainerToken, service: 192.168.0.170:57799 }, ]

2014-12-30 20:06:35,526 DEBUG [DefaultContainerMonitor] - State after reportContainer: DefaultContainerMonitor [allocated=[container_1419934738198_0004_01_000003,], running=[container_1419934738198_0004_01_000002,], completed=[], failed=[]]

////  this line shows the memory is 1300 and cpu core is 7
2014-12-30 20:06:35,526 DEBUG [DefaultContainerLauncher] - Launching container: Container: [ContainerId: container_1419934738198_0004_01_000003, NodeId: yarn-master1:57799, NodeHttpAddress: yarn-master1:8042, Resource: <memory:1300, vCores:7>, Priority: 0, Token: Token { kind: ContainerToken, service: 192.168.0.170:57799 }, ] with commands $JAVA_HOME/bin/java,org.springframework.yarn.container.CommandLineContainerRunner,container-context.xml,yarnContainer,1><LOG_DIR>/Container.stdout,2><LOG_DIR>/Container.stderr

但是,当我尝试运行资源超出限制的应用程序时,其日志显示内存仍为1GB而不是1300,如下所示:
2014-12-30 20:07:05,929 DEBUG [AbstractPollingAllocator] - response has 1 completed containers

//The Same container was stopped because it beyond the limits.
2014-12-30 20:07:05,932 DEBUG [AbstractPollingAllocator] - completed container: container_1419934738198_0004_01_000003 with status=ContainerStatus: [ContainerId: container_1419934738198_0004_01_000003, State: COMPLETE, Diagnostics: Container [pid=10587,containerID=container_1419934738198_0004_01_000003] is running beyond virtual memory limits. Current usage: 86.6 MB of 1 GB physical memory used; 31.8 GB of 2.1 GB virtual memory used. Killing container.
Dump of the process-tree for container_1419934738198_0004_01_000003 :
    |- PID PPID PGRPID SESSID CMD_NAME USER_MODE_TIME(MILLIS) SYSTEM_TIME(MILLIS) VMEM_USAGE(BYTES) RSSMEM_USAGE(PAGES) FULL_CMD_LINE
    |- 10587 32315 10587 10587 (bash) 2 3 12652544 353 /bin/bash -c /home/novelbio/software/jdk//bin/java org.springframework.yarn.container.CommandLineContainerRunner container-context.xml yarnContainer 1>/home/novelbio/software/hadoop/logs/userlogs/application_1419934738198_0004/container_1419934738198_0004_01_000003/Container.stdout 2>/home/novelbio/software/hadoop/logs/userlogs/application_1419934738198_0004/container_1419934738198_0004_01_000003/Container.stderr 
    |- 10761 10587 10587 10587 (java) 108 10 34135896064 21811 /home/novelbio/software/jdk//bin/java org.springframework.yarn.container.CommandLineContainerRunner container-context.xml yarnContainer 

, ExitStatus: 0, ]

关键是在日志中:。当前用法:86.6 MB的 1 GB物理内存使用了而不是1.3GB。

所以我认为我的方法没有生效。谁能告诉我如何正确分配资源?

最佳答案

这是YARN中有问题的 Realm 之一,我相信当YARN中使用越来越多的非MR应用程序时,它们最终会变得更好。我相信您的设置已正确应用,但是YARN的一些奇怪行为导致了这些问题。目前,从应用程序的 Angular 来看,我们几乎无能为力,因为大多数内存设置是在YARN本身中强制执行的,而来自应用程序的请求只是“请求”。

YARN上的Spring XD也依靠同样的东西,值得检查一下我们在其文档中写的内容:https://github.com/spring-projects/spring-xd/wiki/Running-on-YARN。 (请参阅配置YARN内存保留部分)。

我将尝试确保将相同的信息也发送到我们的Spring Hadoop和Spring YARN引用文档。

关于spring - 使用Spring Yarn时如何向容器分配资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27707687/

相关文章:

c# - 在 C# 中使用嵌入式资源图标作为应用程序图标

ios - 本地化语言资源ios

c# - 使用资源文件本地化 ASP.NET WebForm 应用程序

java - 使用 Jackson Framework 进行 @RequestBody 注释的 Spring Boot ObjectMapper

java - Spring是否允许在非抽象中转换抽象bean?

sql - 在Hive上使用索引

hadoop - 在不同的机器组上运行Mapper和Reducer

java - Spring Bean 的真正功效如何

java - 使用 restTemplate 发送带有身份验证 header 的 GET 请求

java - Phoenix 无法正确显示负整数值