如何在使用Spring Yarn时将资源分配给容器?

时间:2014-12-30 14:59:10

标签: spring hadoop resources yarn

我在[github] [1]上使用gradle构建的Spring Yarn示例。我成功地在纱线上运行了自定义服务示例。

但我不知道如何为容器分配特殊资源。我尝试在 CustomAppmaster 的类 StaticEventingAppmaster 中覆盖 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。

所以我认为我的方法没有生效。任何机构都可以告诉我如何正确分配资源吗?

1 个答案:

答案 0 :(得分:0)

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

YARN上的Spring XD依赖于同样的东西,值得检查我们写入其文档的内容:https://github.com/spring-projects/spring-xd/wiki/Running-on-YARN。 (请参阅配置YARN内存预留一节。)

我会尽力确保这些信息也适用于我们的Spring Hadoop和Spring YARN参考文档。