遇到报错: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  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误是由于SparkContext初始化时出现问题导致的。具体来说,第一个引用中的错误是因为系统内存不足,需要增加堆大小。而第二个引用中的错误是因为所需的执行器内存超过了集群的最大阈值。需要检查'yarn.scheduler.maximum-allocation-mb'和'yarn.nodemanager.resource.memory-mb'的值是否正确设置。 解决这个问题的方法取决于具体的情况。如果是第一个引用中的问题,可以通过增加堆大小来解决。可以通过以下方式增加堆大小: ```shell spark-submit --conf spark.driver.memory=4g --conf spark.executor.memory=4g your_app.py ``` 这将把驱动程序和执行器的内存限制都设置为4GB。如果需要更多的内存,可以相应地增加这些值。 如果是第二个引用中的问题,需要检查集群的配置。可以通过以下方式检查和修改配置: 1. 检查'yarn.scheduler.maximum-allocation-mb'和'yarn.nodemanager.resource.memory-mb'的值是否正确设置。可以使用以下命令检查: ```shell yarn getconf -confKey yarn.scheduler.maximum-allocation-mb yarn getconf -confKey yarn.nodemanager.resource.memory-mb ``` 2. 如果这些值太低,可以通过以下方式修改它们: ```shell yarn-site.xml <property> <name>yarn.scheduler.maximum-allocation-mb</name> <value>8192</value> </property> <property> <name>yarn.nodemanager.resource.memory-mb</name> <value>8192</value> </property> ``` 这将把'yarn.scheduler.maximum-allocation-mb'和'yarn.nodemanager.resource.memory-mb'的值都设置为8192MB。如果需要更多的内存,可以相应地增加这些值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值