网络原因造成 spark task 卡住

本文介绍了一种Spark任务中出现的无限卡顿现象,并详细解释了如何定位问题根源,最终发现是由于主机名映射配置缺失导致的任务无法正常读取远程数据块。文章还提供了在大规模集群环境下使用DNS替代hosts文件的建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

主机名映射出错

背景

Yarn集群新加入了一批Spark机器后发现运行Spark任务时,一些task会无限卡住且driver端没有任何提示。

这里写图片描述

解决

进入task卡住的节点查看container stderr日志,发现在获取其他节点block信息时,连接不上其他的机器节点,不停重试。
这里写图片描述
怀疑部分旧节点的/etc/hosts文件被运维更新漏了,查看/etc/hosts,发现没有加入新节点的地址,加入后问题解决。

在集群节点不断增多的情况下,可以使用dns避免某些节点忘记修改/etc/hosts文件导致的错误。

产生原因

在读取shuffle数据时,本地的block会从本地的BlockManager读取数据块,远程的block则通过 BlockTransferService 读取,其中包含了hostname作为地址信息,如果没有hostname和ip的映射信息,则会获取失败,将调用
RetryingBlockFetcher进行重试,如果继续失败则会抛出异常: Exception while beginning fetch …

NettyBlockTransferService

override def fetchBlocks(
    host: String,
    port: Int,
    execId: String,
    blockIds: Array[String],
    listener: BlockFetchingListener): Unit = {
  logTrace(s"Fetch blocks from $host:$port (executor id $execId)")
  try {
    val blockFetchStarter = new RetryingBlockFetcher.BlockFetchStarter {
      override def createAndStart(blockIds: Array[String], listener: BlockFetchingListener) {
        val client = clientFactory.createClient(host, port)
        new OneForOneBlockFetcher(client, appId, execId, blockIds.toArray, listener).start()
      }
    }

    val maxRetries = transportConf.maxIORetries()
    if (maxRetries > 0) {
      // Note this Fetcher will correctly handle maxRetries == 0; we avoid it just in case there's
      // a bug in this code. We should remove the if statement once we're sure of the stability.
      new RetryingBlockFetcher(transportConf, blockFetchStarter, blockIds, listener).start()
    } else {
      blockFetchStarter.createAndStart(blockIds, listener)
    }
  } catch {
    case e: Exception =>
      logError("Exception while beginning fetchBlocks", e)
      blockIds.foreach(listener.onBlockFetchFailure(_, e))
  }
}

RetryingBlockFetcher

private void fetchAllOutstanding() {
  // Start by retrieving our shared state within a synchronized block.
  String[] blockIdsToFetch;
  int numRetries;
  RetryingBlockFetchListener myListener;
  synchronized (this) {
    blockIdsToFetch = outstandingBlocksIds.toArray(new String[outstandingBlocksIds.size()]);
    numRetries = retryCount;
    myListener = currentListener;
  }

  // Now initiate the fetch on all outstanding blocks, possibly initiating a retry if that fails.
  try {
    fetchStarter.createAndStart(blockIdsToFetch, myListener);
  } catch (Exception e) {
    logger.error(String.format("Exception while beginning fetch of %s outstanding blocks %s",
      blockIdsToFetch.length, numRetries > 0 ? "(after " + numRetries + " retries)" : ""), e);

    if (shouldRetry(e)) {
      initiateRetry();
    } else {
      for (String bid : blockIdsToFetch) {
        listener.onBlockFetchFailure(bid, e);
      }
    }
  }
}

读取kafka失败,不断重试

这里写图片描述

原因

防火墙原因连不上9092端口
这里写图片描述

总结

遇到类似问题一般在executor的日志下都能找到结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值