makeCluster无法打开连接 - 错误处理策略?

时间:2017-04-25 13:48:34

标签: r parallel-processing

自动化系统用于启动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之前检查端口是否可以打开?

注意:此系统必须完全自动/自包含。它必须识别错误,处理/修复问题,然后在没有人工干预的情况下继续。

1 个答案:

答案 0 :(得分:1)

此处内部使用的

parallel::makeCluster()parallel::makePSOCKcluster()不提供任何自动重试。如果您查看parallel::makePSOCKcluster()的代码,则可以基于设置每个工作人员的parallel:::newPSOCKnode()来实现您自己的版本。这是一个内部功能,因此应该被视为&#34; hack&#34;。

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