갑자기 오류가 발생했습니다: ERROR spark.SparkContext: Error initializing SparkContext.
Eclipse에서 스파크 프로젝트를 개발하고 spark에서 프로그램을 직접 실행하려고 시도했을 때 다음과 같은 오류가 발생했습니다.
이것은 JVM이 신청한 메모리가 부족해서 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
main 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을 줬어요.
그리고 다시 실행하면 정상적으로 결과가 나옵니다.
코드에 지정할 수도 있습니다.
val conf = new SparkConf().setAppName("word count") conf.set("spark.testing.memory", "1g")//뒤에 512m 이상이면 됩니다.
[java] view plain
copy
/**
* Return the total amount of memory shared between execution and storage, in bytes.
*/
private def getMaxMemory(conf: SparkConf): Long = {
val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)
val reservedMemory = conf.getLong("spark.testing.reservedMemory",
if (conf.contains("spark.testing")) 0 else RESERVED_SYSTEM_MEMORY_BYTES)
val minSystemMemory = reservedMemory * 1.5
if (systemMemory < minSystemMemory) {
throw new IllegalArgumentException(s"System memory $systemMemory must " +
s"be at least $minSystemMemory. Please use a larger heap size.")
}
val usableMemory = systemMemory - reservedMemory
val memoryFraction = conf.getDouble("spark.memory.fraction", 0.75)
(usableMemory * memoryFraction).toLong
}
그래서 여기는 주로 val systemMemory = conf.getLong("spark.testing.memory", Runtime.getRuntime.maxMemory)입니다.
conf.getLong () 의 정의와 해석은
[java] view plain copy getLong(key: String, defaultValue: Long): Long Get a parameter as a long, falling back to a default if not set
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.