TaskSchedulerImpl:初始作业尚未接受任何资源。 (火花错误)

TaskSchedulerImpl: Initial job has not accepted any resources. (Error in Spark)

我正在尝试 运行 SparkPi 我的独立模式集群上的示例。

package org.apache.spark.examples
import scala.math.random
import org.apache.spark._

/** Computes an approximation to pi */
object SparkPi {
  def main(args: Array[String]) {
    val conf = new SparkConf().setAppName("SparkPi")
      .setMaster("spark://192.168.17.129:7077")
      .set("spark.driver.allowMultipleContexts", "true")
    val spark = new SparkContext(conf)
    val slices = if (args.length > 0) args(0).toInt else 2
    val n = math.min(100000L * slices, Int.MaxValue).toInt // avoid overflow
    val count = spark.parallelize(1 until n, slices).map { i =>
    val x = random * 2 - 1
    val y = random * 2 - 1
    if (x*x + y*y < 1) 1 else 0
    }.reduce(_ + _)
    println("Pi is roughly " + 4.0 * count / n)
    spark.stop()
    }
}

注意:我在这一行做了一点改动:

val conf = new SparkConf().setAppName("SparkPi")
  .setMaster("spark://192.168.17.129:7077")
  .set("spark.driver.allowMultipleContexts", "true")

问题: 我正在使用 spark-shell(Scala 接口)来 运行 这段代码。当我尝试此代码时,我反复收到此错误:

15/02/09 06:39:23 WARN TaskSchedulerImpl: Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient memory

注意: 我可以在我的 Master 的 WebUI 中看到我的工人,而且我可以在 运行 应用程序中看到一个新工作 部分。但是这个应用程序没有结束,我反复看到错误。

问题是什么?

谢谢

如果你想从 spark shell 中 运行 ,然后使用参数 --master spark://192.168.17.129:7077 启动 shell 并输入以下代码:

import scala.math.random
import org.apache.spark._
val slices = 10
val n = math.min(100000L * slices, Int.MaxValue).toInt // avoid overflow
val count = sc.parallelize(1 until n, slices).map { i =>
    val x = random * 2 - 1
    val y = random * 2 - 1
    if (x*x + y*y < 1) 1 else 0
}.reduce(_ + _)
println("Pi is roughly " + 4.0 * count / n)

否则,将代码编译成 jar 并 运行 使用 spark-submit。但是从代码中删除 setMaster 并将其作为 'master' 参数添加到 spark-submit 脚本。同时从代码中删除 allowMultipleContexts 参数。

您只需要一个 spark 上下文。