2017-04-25 55 views
0

使用自动化系统启动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?

注意:该系统必须是完全自动/自包含的。它必须识别错误,处理/解决问题,然后不进行手动干预。

回答

1

parallel::makeCluster()parallel::makePSOCKcluster()此处内部使用,不提供任何自动重试。如果您查看parallel::makePSOCKcluster()的代码,则可以根据设置每个工作人员的parallel:::newPSOCKnode()实施您自己的版本。这是一个内部功能,所以它应该被认为是“黑客”。

future包(我是作者)中,有future::makeClusterPSOCK()和伴侣future::makeNodePSOCK() - 都是公共API的一部分。这为您提供构建模块来运行您自己的改进版本。另外,您可以编写自己的函数myCreateNode()来设置群集节点,并重试并使用它作为cl <- future::makeClusterPSOCK(..., makeNode = myCreateNode)。对不起,这就是我现在所有的时间。