Suddenly encountered an error: Error spark. Sparkcontext:error initializing Sparkcontext.

Source: Internet
Author: User


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

When you develop a spark project in Eclipse and try to run the program directly in Spark, you encounter the following error:


Obviously, this is a JVM application that does not have enough memory to start Sparkcontext. But how do you set it up?

But I checked the startup script.

#!/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

when the memory given to driver is trying to increase to 400M .

is still the following error

Exception in thread "main" Java.lang.IllegalArgumentException:System memory 402128896 must is at least 4.718592E8. Please use a larger heap size.

Now you can turn it up a little bit and give it to 1g.

And then run it again and get the results.

You can also specify in the code:

Val conf = new sparkconf (). Setappname ("word count")
Conf.set ("Spark.testing.memory", "1g")//after the value is greater than 512m can

[Java]View PlainCopy 
  1. /**  
  2.    * return the total amount of memory  shared between execution and storage, in bytes.  
  3.    */ &NBSP;&NBSP;
  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 Elsereserved_system_memory_bytes)
  8.     val minsystemmemory = reservedmemory *   1.5 &NBSP;&NBSP;
  9.     if   (systemmemory <  minsystemmemory)  {  
  10.        throw &NBSP; new  illegalargumentexception (s &NBSP;+&NBSP;&NBSP;
  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 " ,&NBSP; 0.75
  15. (Usablememory * memoryfraction). Tolong
  16. }

So, here is the main val systemmemory = Conf.getlong ("Spark.testing.memory", Runtime.getRuntime.maxMemory).

The definition and interpretation of conf.getlong () is

[Java]View PlainCopy 
  1. getLong (Key: string, defaultvalue: long):  long  
  2. Get a  Parameter as a long , falling back to  a  default &NBSP; if  not set  


Suddenly encountered an error: Error spark. Sparkcontext:error initializing Sparkcontext.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.