使用自动化系统启动R脚本,该脚本使用makeCluster在具有36个CPU的计算机上打开35个节点的集群。 (AWS c4.8xlarge运行最新的Ubuntu和R)makeCluster无法打开连接 - 错误处理策略?
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?
注意:该系统必须是完全自动/自包含的。它必须识别错误,处理/解决问题,然后不进行手动干预。