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

在Eclipse中使用Spark进行开发时遇到报错:'System memory 100663296 must be at least 4.718592E8',原因是JVM内存不足。通过检查启动脚本和调整Spark配置,发现driver内存设置不足。将driver内存增加到1GB后,通过代码`conf.set("spark.testing.memory", "1g")`设置SparkConf,解决了内存不足的问题,成功初始化SparkContext。" 111016309,10296209,Python实现概率分布随机选择,"['Python编程', '概率计算', '随机数生成']


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

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


很明显,这是JVM申请的memory不够导致无法启动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

<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即可

[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  

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值