갑자기 오류가 발생했습니다: ERROR spark.SparkContext: Error initializing SparkContext.

2735 단어
java.lang.IllegalArgumentException: System memory 100663296 must be at least 4.718592E8. Please use a larger heap size.
Eclipse에서 스파크 프로젝트를 개발하고 spark에서 프로그램을 직접 실행하려고 시도했을 때 다음과 같은 오류가 발생했습니다.
이것은 JVM이 신청한 메모리가 부족해서 SparkContext를 시작할 수 없다는 것이 분명하다.근데 어떻게 해야 되지?
그런데 시작 스크립트를 체크해 봤어요.
#!/bin/bash
/usr/local/spark-1.6.0/bin/spark-submit  \
--class cn.spark.study.Opt17_WordCount \
--num-executors 3 \
--driver-memory <strong>100m </strong>\ 
--executor-memory <strong>100m </strong>\
--executor-cores 3 \
/root/sparkstudy/Java/spark-study-java-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
--master  spark://yun01:7077
 main    driver  

드라이버에 메모리를 400M까지 늘리려고 시도할 때
여전히 아래와 같은 잘못을 폭로했다
Exception in thread "main"java.lang.IllegalArgumentException: System memory 402128896 must be at least 4.718592E8. Please use a larger heap size.
이때 다시 크게 할 수 있어요. 1g을 줬어요.
그리고 다시 실행하면 정상적으로 결과가 나옵니다.
코드에 지정할 수도 있습니다.
 val conf = new SparkConf().setAppName("word count") conf.set("spark.testing.memory", "1g")//뒤에 512m 이상이면 됩니다.
[java]  view plain
 copy
 
/** 
   * Return the total amount of memory shared between execution and storage, in bytes. 
   */  
  private def getMaxMemory(conf: SparkConf): Long = {  
    val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)  
    val reservedMemory = conf.getLong("spark.testing.reservedMemory",  
      if (conf.contains("spark.testing")) 0 else RESERVED_SYSTEM_MEMORY_BYTES)  
    val minSystemMemory = reservedMemory * 1.5  
    if (systemMemory < minSystemMemory) {  
      throw new IllegalArgumentException(s"System memory $systemMemory must " +  
        s"be at least $minSystemMemory. Please use a larger heap size.")  
    }  
    val usableMemory = systemMemory - reservedMemory  
    val memoryFraction = conf.getDouble("spark.memory.fraction", 0.75)  
    (usableMemory * memoryFraction).toLong  
  }  
그래서 여기는 주로 val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)입니다.
conf.getLong () 의 정의와 해석은

[java]  view plain  copy   getLong(key: String, defaultValue: Long): Long   Get a parameter as a long, falling back to a default if not set  


좋은 웹페이지 즐겨찾기