我的目的是在同一台计算机/服务器上的R内启动两个或多个h2o群集/实例(不是两个或更多节点!),以使多个用户能够同时与h2o连接时间。此外,我希望能够单独关闭和重新启动集群,也可以从R中开始。
我已经知道我无法简单地从R中控制多个h2o集群,因此我尝试从Windows 10中的命令行启动两个集群:
java -Xmx1g -jar h2o.jar -name testCluster1 -nthreads 1 -port 54321
java -Xmx1g -jar h2o.jar -name testCluster2 -nthreads 1 -port 54323
这对我来说很好用:
library(h2o)
h2o.init(startH2O = FALSE, ip = "localhost", port = 54321)
Connection successful!
R is connected to the H2O cluster:
H2O cluster uptime: 4 minutes 8 seconds
H2O cluster version: 3.8.3.2
H2O cluster name: testCluster
H2O cluster total nodes: 1
H2O cluster total memory: 0.87 GB
H2O cluster total cores: 4
H2O cluster allowed cores: 1
H2O cluster healthy: TRUE
H2O Connection ip: localhost
H2O Connection port: 54321
H2O Connection proxy: NA
R Version: R version 3.2.5 (2016-04-14)
h2o.init(startH2O = FALSE, ip = "localhost", port = 54323)
Connection successful!
R is connected to the H2O cluster:
H2O cluster uptime: 3 minutes 32 seconds
H2O cluster version: 3.8.3.2
H2O cluster name: testCluster2
H2O cluster total nodes: 1
H2O cluster total memory: 0.87 GB
H2O cluster total cores: 4
H2O cluster allowed cores: 1
H2O cluster healthy: TRUE
H2O Connection ip: localhost
H2O Connection port: 54323
H2O Connection proxy: NA
R Version: R version 3.2.5 (2016-04-14)
现在,我希望通过system()命令在R中执行相同的操作。
launchH2O <- as.character("java -Xmx1g -jar h2o.jar -name testCluster -nthreads 1 -port 54321")
system(command = launchH2O, intern =TRUE)
但是我收到一条错误消息:
[1] "Error: Unable to access jarfile h2o.jar"
attr(,"status")
[1] 1
Warning message:
running command 'java -Xmx1g -jar h2o.jar -name testCluster -nthreads 1 -port 54321' had status 1
尝试
system2(command = launchH2O)
我收到一条警告消息,我无法连接群集:
system2(command = launchH2O)
Warning message:
running command '"java -Xmx1g -jar h2o.jar -name testCluster -nthreads 1 -port 54321"' had status 127
h2o.init(startH2O = FALSE, ip = "localhost", port = 54321)
Error in h2o.init(startH2O = FALSE, ip = "localhost", port = 54321) :
Cannot connect to H2O server. Please check that H2O is running at http://localhost:54321/
如何从R中启动/关闭两个或多个h2o集群? 提前谢谢!
注1:我只使用本地Windows设备进行测试,实际上我想在Linux服务器上创建多个h2o集群。
注2:我用R GUI(3.2.5)和R Studio(版本0.99.892)尝试了它,我以管理员身份运行它们。 h2o.jar文件位于我的工作目录中,我的Java版本是(Build 1.8.0_91-b14)。
注3:系统信息: - h2o&amp; h2o R包版本:3.8.3.2 - Windows 10 Home,版本1511 - 16个RAM,Intel Core i5-6200U CPU,2,30 GHz
答案 0 :(得分:3)
编辑:我已根据评论更改为intern = FALSE,在以下示例中
你应该只需要更改目录;它是否设置wait = FALSE(在后台运行命令)。
launchH2O <- "java -Xmx1g -jar h2o.jar -name testCluster -nthreads 1 -port 54321"
savewd <- setwd("/path/to/h2ojar/")
system(command = launchH2O, intern =FALSE wait=FALSE)
setwd(savewd)
最后一行,savewd
的分配只是为了保留工作目录。或者,这也应该有效:
launchH2O <- "java -Xmx1g -jar /path/to/h2ojar/h2o.jar -name testCluster -nthreads 1 -port 54321"
system(command = launchH2O, intern =FALSE, wait=FALSE)
在Linux上,有另一种方式:
launchH2O <- "bash -c 'nohup java -Xmx1g -jar /path/to/h2ojar/h2o.jar -name testCluster -nthreads 1 -port 54321 &'"
system(command = launchH2O, intern =FALSE)
(因为最后一个命令明确地将它放在后台,我认为你不需要设置wait=FALSE
。)