我的意图是在同一台计算机/服务器上从 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 & h2o R 包版本:3.8.3.2 - Windows 10 家庭版,版本 1511 - 16 内存,英特尔酷睿 i5-6200U CPU 2.30 GHz
最佳答案
编辑:在下面的示例中,我已根据评论更改为 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
。)
关于r - 从 R 中启动多个 h2o 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38441250/