web-dev-qa-db-ja.com

大規模なデータセットでsparkを実行中に「sparkContextがシャットダウンされました」

特定のデータサイズ(〜2,5gb)を超えてクラスターでsparkJobを実行すると、「SparkContextがシャットダウンされたためジョブがキャンセルされました」または「executorが失われました」のいずれかが発生します。糸のGUIを見ると、殺された仕事が成功したことがわかります。 500MBのデータで実行しても問題はありません。私が解決策を探していたところ、次のことがわかりました。「一部のエグゼキュータは、予想よりも多くのメモリを要求するため、yarnが実行を停止しているようです」

それをデバッグする方法の提案はありますか?

私が送信するコマンドsparkジョブを使用して:

/opt/spark-1.5.0-bin-hadoop2.4/bin/spark-submit  --driver-memory 22g --driver-cores 4 --num-executors 15 --executor-memory 6g --executor-cores 6  --class sparkTesting.Runner   --master yarn-client myJar.jar jarArguments

とsparkContextの設定

val sparkConf = (new SparkConf()
    .set("spark.driver.maxResultSize", "21g")
    .set("spark.akka.frameSize", "2011")
    .set("spark.eventLog.enabled", "true")
    .set("spark.eventLog.enabled", "true")
    .set("spark.eventLog.dir", configVar.sparkLogDir)
    )

失敗する単純化されたコードはそのように見えます

 val hc = new org.Apache.spark.sql.Hive.HiveContext(sc)
val broadcastParser = sc.broadcast(new Parser())

val featuresRdd = hc.sql("select "+ configVar.columnName + " from " + configVar.Table +" ORDER BY Rand() LIMIT " + configVar.Articles)
val myRdd : org.Apache.spark.rdd.RDD[String] = featuresRdd.map(doSomething(_,broadcastParser))

val allWords= featuresRdd
  .flatMap(line => line.split(" "))
  .count

val wordQuantiles= featuresRdd
  .flatMap(line => line.split(" "))
  .map(Word => (Word, 1))
  .reduceByKey(_ + _)
  .map(pair => (pair._2 , pair._2))
  .reduceByKey(_+_)
  .sortBy(_._1)
  .collect
  .scanLeft((0,0.0)) ( (res,add) => (add._1, res._2+add._2) )
  .map(entry => (entry._1,entry._2/allWords))

val dictionary = featuresRdd
  .flatMap(line => line.split(" "))
  .map(Word => (Word, 1))
  .reduceByKey(_ + _) // here I have Rdd of Word,count tuples
  .filter(_._2 >= moreThan)
  .filter(_._2 <= lessThan)
  .filter(_._1.trim!=(""))
  .map(_._1)
  .zipWithIndex
  .collect
  .toMap

そしてエラースタック

Exception in thread "main" org.Apache.spark.SparkException: Job cancelled because SparkContext was shut down
at org.Apache.spark.scheduler.DAGScheduler$$anonfun$cleanUpAfterSchedulerStop$1.apply(DAGScheduler.scala:703)
at org.Apache.spark.scheduler.DAGScheduler$$anonfun$cleanUpAfterSchedulerStop$1.apply(DAGScheduler.scala:702)
at scala.collection.mutable.HashSet.foreach(HashSet.scala:79)
at org.Apache.spark.scheduler.DAGScheduler.cleanUpAfterSchedulerStop(DAGScheduler.scala:702)
at org.Apache.spark.scheduler.DAGSchedulerEventProcessLoop.onStop(DAGScheduler.scala:1511)
at org.Apache.spark.util.EventLoop.stop(EventLoop.scala:84)
at org.Apache.spark.scheduler.DAGScheduler.stop(DAGScheduler.scala:1435)
at org.Apache.spark.SparkContext$$anonfun$stop$7.apply$mcV$sp(SparkContext.scala:1715)
at org.Apache.spark.util.Utils$.tryLogNonFatalError(Utils.scala:1185)
at org.Apache.spark.SparkContext.stop(SparkContext.scala:1714)
at org.Apache.spark.scheduler.cluster.YarnClientSchedulerBackend$MonitorThread.run(YarnClientSchedulerBackend.scala:146)
at org.Apache.spark.scheduler.DAGScheduler.runJob(DAGScheduler.scala:567)
at org.Apache.spark.SparkContext.runJob(SparkContext.scala:1813)
at org.Apache.spark.SparkContext.runJob(SparkContext.scala:1826)
at org.Apache.spark.SparkContext.runJob(SparkContext.scala:1839)
at org.Apache.spark.SparkContext.runJob(SparkContext.scala:1910)
at org.Apache.spark.rdd.RDD.count(RDD.scala:1121)
at sparkTesting.InputGenerationAndDictionaryComputations$.createDictionary(InputGenerationAndDictionaryComputations.scala:50)
at sparkTesting.Runner$.main(Runner.scala:133)
at sparkTesting.Runner.main(Runner.scala)
at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:62)
at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
at Java.lang.reflect.Method.invoke(Method.Java:483)
at org.Apache.spark.deploy.SparkSubmit$.org$Apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:672)
at org.Apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:180)
at org.Apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:205)
at org.Apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:120)
at org.Apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
11

答えが見つかりました。

私のテーブルは20GBのavroファイルとして保存されました。執行者がそれを開こうとしたとき。それぞれが20GBをメモリにロードする必要がありました。 avroの代わりにcsvを使用して解決しました

7

「SparkContext is shutdown」エラーの別の考えられる原因は、他のコードを評価した後にjarファイルをインポートしていることです。 (これはSparkノートブックでのみ発生する可能性があります。)

問題を解決するには、すべての:cp myjar.jarステートメントをファイルの先頭に追加します。

症状は、Executorタスクの1つのOutOfMemoryエラーの典型的なものです。ジョブを起動するときにエグゼキュータのメモリを増やしてみてください。 saprk-submit、spark-Shellなどのパラメータ--executor-memoryを参照してください。デフォルト値は1Gです

1