【问题标题】:makeCluster cannot open the connection -- error handling strategies?makeCluster 无法打开连接——错误处理策略?
【发布时间】: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


    【解决方案1】:

    parallel::makeCluster(),或parallel::makePSOCKcluster()在此内部使用,不提供任何自动重试。如果您查看parallel::makePSOCKcluster() 的代码,您会根据设置每个单独工作人员的parallel:::newPSOCKnode() 实现您自己的版本。这是一个内部函数,所以它应该被认为是“hack”。

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

    【讨论】:

      猜你喜欢
      • 2017-10-09
      • 1970-01-01
      • 2017-01-18
      • 2014-12-19
      • 2010-12-07
      • 2017-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多