【发布时间】:2017-04-25 13:48:34
【问题描述】:
一个自动化系统用于启动一个 R 脚本,该脚本使用 makeCluster 在具有 36 个 CPU 的机器上打开一个由 35 个节点组成的集群。 (AWS c4.8xlarge 运行最新的 Ubuntu 和 R)
n.nodes = 35
cl <- makeCluster(n.nodes,
outfile = "debug.txt")
以下写入 debug.txt 的错误经常出现
starting worker pid=2017 on localhost:11823 at 21:15:57.390
Error in socketConnection(master, port = port, blocking = TRUE, open = "a+b", :
cannot open the connection
Calls: <Anonymous> ... doTryCatch -> recvData -> makeSOCKmaster -> socketConnection
In addition: Warning message:
In socketConnection(master, port = port, blocking = TRUE, open = "a+b", :
localhost:11823 cannot be opened
Execution halted
pid 和端口号是特定于会话的。遇到此错误时程序无法继续。
问题 1: 是否有错误处理方法可以识别出这种情况并尝试再次创建集群?
注意:以下不起作用
attempt=0
while(dim(showConnections())[1] < n.nodes && attempt<=25){ # 25 chancees to create n.nodes connections
print(attempt)
closeAllConnections() # Close any open connections
portnum = round(runif(1,11000,11998)) # Randomly Choose a Port
tryCatch({ # Try to create the cluster
evalWithTimeout({
cl <- makeCluster(n.nodes,
outfile = "debug.txt",
port=portnum)
},timeout = 120) # Give it two minutes and then stop trying
},TimeoutException = function(x) {print(paste("Failed to Create Cluster",portnum))}) # If it fails, print the portnum it tried
attempt=attempt+1 # Update attempt
Sys.sleep(2) # Take a breather
}
问题2:如果没有办法自动重试制作集群,有没有办法在尝试运行makeCluster之前检查端口是否可以打开?
注意:此系统必须完全自动化/独立。它必须识别错误,处理/修复问题,然后在没有人工干预的情况下继续。
【问题讨论】:
标签: r parallel-processing