遇到报错:ERROR spark.SparkContext: Error initializing SparkContext

java.lang.IllegalArgumentException: System memory 100663296 must be at least 4.718592E8. Please use a larger heap size.

在Eclipse里开发Spark项目,尝试直接在spark里运行程序的时候,遇到下面这个报错:

很明显,这是JVM申请的memory不够导致无法启动SparkContext。但是该怎么设呢?

但是检查了一下启动脚本

[java] view plain copy

  1. #!/bin/bash  
  2. /usr/local/spark-1.6.0/bin/spark-submit  \  
  3. --class cn.spark.study.Opt17_WordCount \  
  4. --num-executors 3 \  
  5. --driver-memory <strong>100m </strong>\   
  6. --executor-memory <strong>100m </strong>\  
  7. --executor-cores 3 \  
  8. /root/sparkstudy/Java/spark-study-java-0.0.1-SNAPSHOT-jar-with-dependencies.jar \  
  9. --master  spark://yun01:7077  
  1. <pre code_snippet_id="1674698" snippet_file_name="blog_20160506_2_7762008" name="code" class="java" style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px;">  
 

看来是driver内存不足,当给了 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(应该是从spark升级1.5或者1.6之后才出现这样的问题,)

然后再次运行之后正常得出结果

还可以指定在代码中 :

 val conf = new SparkConf().setAppName("word count")
 conf.set("spark.testing.memory", "1g")//后面的值大于512m即可

原链接:https://blog.csdn.net/wangshuminjava/article/details/79598720

[java] view plain copy

 在CODE上查看代码片派生到我的代码片

  1. /** 
  2.    * Return the total amount of memory shared between execution and storage, in bytes. 
  3.    */  
  4.   private def getMaxMemory(conf: SparkConf): Long = {  
  5.     val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)  
  6.     val reservedMemory = conf.getLong("spark.testing.reservedMemory",  
  7.       if (conf.contains("spark.testing")) 0 else RESERVED_SYSTEM_MEMORY_BYTES)  
  8.     val minSystemMemory = reservedMemory * 1.5  
  9.     if (systemMemory < minSystemMemory) {  
  10.       throw new IllegalArgumentException(s"System memory $systemMemory must " +  
  11.         s"be at least $minSystemMemory. Please use a larger heap size.")  
  12.     }  
  13.     val usableMemory = systemMemory - reservedMemory  
  14.     val memoryFraction = conf.getDouble("spark.memory.fraction", 0.75)  
  15.     (usableMemory * memoryFraction).toLong  
  16.   }  

所以,这里主要是val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)。

conf.getLong()的定义和解释是

[java] view plain copy

 在CODE上查看代码片派生到我的代码片

  1. getLong(key: String, defaultValue: Long): Long  
  2. Get a parameter as a long, falling back to a default if not set  

猜你喜欢

转载自blog.csdn.net/qq_41587243/article/details/85699351