Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set heap size in spark within the Eclipse environment?

I am trying to run the simple following code using spark within Eclipse:

import org.apache.spark.sql.SQLContext
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
object jsonreader {  
  def main(args: Array[String]): Unit = {
    println("Hello, world!")
    val conf = new SparkConf()
      .setAppName("TestJsonReader")
      .setMaster("local")
      .set("spark.driver.memory", "3g") 
    val sc = new SparkContext(conf)

    val sqlContext = new SQLContext(sc)
    val df = sqlContext.read.format("json").load("text.json")

    df.printSchema()
    df.show   
  }
}

However, I get the following errors:

16/08/18 18:05:28 ERROR SparkContext: Error initializing SparkContext.
java.lang.IllegalArgumentException: System memory 259522560 must be at least 471859200. Please increase heap size using the --driver-memory option or spark.driver.memory in Spark configuration.

I followed different tutorials like this one: How to set Apache Spark Executor memory. Most of time either I use --driver-memory option (not possible with Eclipse) or by modifiying the spark configuration but there is no corresponding file.

Does anyone have any idea about how to solve this issue within Eclipse environment?

like image 483
Yassir S Avatar asked Aug 18 '16 16:08

Yassir S


People also ask

How do I set heap size in Eclipse?

On the Eclipse menu, clicks Run -> Run Configurations.. , select the Java application we want to run, click on the Arguments tab, VM arguments section, and adjust a better Java initial maximum heap size.

How do you fix heap memory in Spark?

You can resolve it by setting the partition size: increase the value of spark. sql. shuffle. partitions.

What is heap size in Eclipse?

Now, the maximum Java heap space for eclipse is set to 512 megabytes. If you still see OutOfMemoryError in Eclipse, you probably need to investigate more which plugin/feature or project is creating the problem. Disabling some plugins or projects will certainly help to free some memory on Eclipse.

How do I see heap memory in Eclipse?

Measuring the memory usage of eclipseGoto Window > Preferences > General and enable Show heap status and click OK.


2 Answers

In Eclipse go to Run > Run Configurations... > Arguments > VM arguments and set max heapsize like -Xmx512m.

like image 94
abaghel Avatar answered Sep 24 '22 23:09

abaghel


I had this issue as well and this is how I solved it. Thought it might be helpful.

val conf: SparkConf = new SparkConf().setMaster("local[4]").setAppName("TestJsonReader").set("spark.driver.host", "localhost")
conf.set("spark.testing.memory", "2147480000")
like image 40
Duy Bui Avatar answered Sep 24 '22 23:09

Duy Bui