2014-12-30 42 views
0

我正在使用gradle構建的[github] [1]上的Spring Yarn示例。我成功地運行紗線上的custom-amservice示例。如何在使用春紗時將資源分配給容器?

但我不知道如何分配特殊資源的容器。我試圖重寫onContainerAllocatedStaticEventingAppmaster類在我CustomAppmaster 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 

然而,當我試圖運行一個應用程序,它的資源了極限,它的日誌顯示內存保持,而不是1300 1GB,只是看到如下:

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的使用1GB物理內存而不是1.3GB。

所以我認爲我的方法沒有生效。任何機構可以告訴我如何正確分配資源?

回答

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 ref文檔。

相關問題