program tip

Apache Spark Executor 메모리를 설정하는 방법

radiobox 2020. 7. 25. 10:46
반응형

Apache Spark Executor 메모리를 설정하는 방법


Apache spark executor 노드에 사용 가능한 메모리를 늘리려면 어떻게해야합니까?

Apache Spark에로드하는 데 적합한 2GB 파일이 있습니다. 나는 지금 한 컴퓨터에서 아파치 스파크를 실행하고 있으므로 드라이버와 실행기가 같은 컴퓨터에 있습니다. 기계에는 8GB의 메모리가 있습니다.

메모리에 캐시되도록 파일을 설정 한 후 파일 줄 수를 세려고하면 다음 오류가 발생합니다.

2014-10-25 22:25:12 WARN  CacheManager:71 - Not enough space to cache partition rdd_1_1 in memory! Free memory is 278099801 bytes.

나는 문서에서보고 여기 와 설정 spark.executor.memory4g$SPARK_HOME/conf/spark-defaults.conf

UI는이 변수가 Spark 환경에서 설정되었음을 보여줍니다. 여기에서 스크린 샷을 찾을 수 있습니다

그러나 Executor 탭으로 이동하면 단일 Executor의 메모리 제한은 여전히 ​​265.4MB로 설정됩니다. 나는 여전히 같은 오류가 발생합니다.

여기에 언급 된 다양한 것을 시도 했지만 여전히 오류가 발생하고 설정을 변경 해야하는 곳을 명확하게 알지 못합니다.

spark-shell에서 대화식으로 코드를 실행하고 있습니다.


로컬 모드에서 Spark를 실행하고 있으므로 알다시피 설정 spark.executor.memory이 적용되지 않습니다. 그 이유는 작업자가 spark-shell 을 시작할 때 시작하는 드라이버 JVM 프로세스 내에서 "작동" 하고 그에 사용되는 기본 메모리가 512M 이기 때문입니다 . 5gspark.driver.memory 와 같이 더 높은 값 으로 설정 하여이를 늘릴 수 있습니다 . 다음 중 하나를 수행하면됩니다.

  • 속성 파일에서 설정 (기본값은 spark-defaults.conf)

    spark.driver.memory              5g
    
  • 또는 런타임에 구성 설정을 제공하여

    $ ./bin/spark-shell --driver-memory 5g
    

이미 너무 늦었 기 때문에 프로세스가 이미 약간의 메모리로 시작했기 때문에 응용 프로그램에서 설정하면이 작업을 수행 할 수 없습니다.

그 이유 265.4 MB는 그 스파크입니다 바치 spark.storage.memoryFraction * spark.storage.safetyFraction 저장 메모리의 총량을 기본적으로 그들은 0.6과 0.9이다.

512 MB * 0.6 * 0.9 ~ 265.4 MB

따라서 RDD 스토리지에 전체 드라이버 메모리를 사용할 수있는 것은 아닙니다.

그러나 클러스터에서이를 실행하기 시작 spark.executor.memory하면 Spark의 메모리 캐시에 할당 할 양을 계산할 때 설정이 인계됩니다.


또한 로컬 모드의 경우 jvm을 시작하기 전에 드라이버 메모리의 양을 설정해야합니다.

bin/spark-submit --driver-memory 2g --class your.class.here app.jar

기본 512M 대신 2G로 JVM이 시작됩니다.
자세한 내용은 여기 :

로컬 모드의 경우 하나의 실행 프로그램 만 있으며이 실행 프로그램이 드라이버이므로 드라이버 메모리를 대신 설정해야합니다. * 로컬 모드에서 spark-submit을 실행할 때 이미 기본 메모리 설정으로 JVM이 시작되었으므로 conf에서 "spark.driver.memory"를 설정하면 실제로 아무런 작업도 수행되지 않습니다. 대신 다음과 같이 spark-submit을 실행해야합니다.


분명히, 질문은 원사가 아닌 로컬 모드에서 실행된다고 결코 말하지 않습니다. 어떻게 든 spark-default.conf 변경을 작동시킬 수 없었습니다. 대신 나는 이것을 시도했고 그것은 나를 위해 일했다.

bin/spark-shell --master yarn --num-executors 6  --driver-memory 5g --executor-memory 7g

(8g의 범프 범프 실행기 메모리는 원사 구성에 약간의 제한이 있습니다.)


드라이버 메모리를 늘려야합니다. Mac에서 (즉, 로컬 마스터에서 실행할 때) 기본 드라이버 메모리는 1024M입니다. 따라서 기본적으로 380Mb가 실행기에 할당됩니다.

스크린 샷

[ --driver-memory 2G ] 를 늘리면 실행기 메모리가 ~ 950Mb로 증가했습니다.여기에 이미지 설명을 입력하십시오


spark / conf 디렉토리에 spark-env.sh라는 파일을 만들고이 줄을 추가하십시오

SPARK_EXECUTOR_MEMORY=2000m #memory size which you want to allocate for the executor

Grega가 제출 한 답변으로 문제를 해결하는 데 도움이되었습니다. Docker 컨테이너 내의 Python 스크립트에서 로컬로 Spark를 실행하고 있습니다. 처음에 Spark에서 일부 데이터를 처리 할 때 Java 메모리 부족 오류가 발생했습니다. 그러나 스크립트에 다음 줄을 추가하여 더 많은 메모리를 할당 할 수있었습니다.

conf=SparkConf()
conf.set("spark.driver.memory", "4g") 

Spark를 시작하는 데 사용하는 Python 스크립트의 전체 예는 다음과 같습니다.

import os
import sys
import glob

spark_home = '<DIRECTORY WHERE SPARK FILES EXIST>/spark-2.0.0-bin-hadoop2.7/'
driver_home = '<DIRECTORY WHERE DRIVERS EXIST>'

if 'SPARK_HOME' not in os.environ:
    os.environ['SPARK_HOME'] = spark_home 

SPARK_HOME = os.environ['SPARK_HOME']

sys.path.insert(0,os.path.join(SPARK_HOME,"python"))
for lib in glob.glob(os.path.join(SPARK_HOME, "python", "lib", "*.zip")):
    sys.path.insert(0,lib);

from pyspark import SparkContext
from pyspark import SparkConf
from pyspark.sql import SQLContext

conf=SparkConf()
conf.set("spark.executor.memory", "4g")
conf.set("spark.driver.memory", "4g")
conf.set("spark.cores.max", "2")
conf.set("spark.driver.extraClassPath",
    driver_home+'/jdbc/postgresql-9.4-1201-jdbc41.jar:'\
    +driver_home+'/jdbc/clickhouse-jdbc-0.1.52.jar:'\
    +driver_home+'/mongo/mongo-spark-connector_2.11-2.2.3.jar:'\
    +driver_home+'/mongo/mongo-java-driver-3.8.0.jar') 

sc = SparkContext.getOrCreate(conf)

spark = SQLContext(sc)

다음 예제를 사용하여 명령을 작성할 수 있습니다

 spark-submit    --jars /usr/share/java/postgresql-jdbc.jar    --class com.examples.WordCount3  /home/vaquarkhan/spark-scala-maven-project-0.0.1-SNAPSHOT.jar --jar  --num-executors 3 --driver-memory 10g **--executor-memory 10g** --executor-cores 1  --master local --deploy-mode client  --name wordcount3 --conf "spark.app.id=wordcount" 

Spark executor memory is required for running your spark tasks based on the instructions given by your driver program. Basically, it requires more resources that depends on your submitted job.

Executor memory includes memory required for executing the tasks plus overhead memory which should not be greater than the size of JVM and yarn maximum container size.

Add the following parameters in spark-defaults.conf

spar.executor.cores=1

spark.executor.memory=2g

If you using any cluster management tools like cloudera manager or amabari please refresh the cluster configuration for reflecting the latest configs to all nodes in the cluster.

Alternatively, we can pass the executor core and memory value as an argument while running spark-submit command along with class and application path.

Example:

spark-submit \

  --class org.apache.spark.examples.SparkPi \

  --master yarn \

  --deploy-mode cluster \  # can be client for client mode

  --executor-memory 2G \

  --num-executors 5 \

  /path/to/examples.jar \

  1000

you mentioned that you are running yourcode interactivly on spark-shell so, while doing if no proper value is set for driver-memory or executor memory then spark defaultly assign some value to it, which is based on it's properties file(where default value is being mentioned).

I hope you are aware of the fact that there is one driver(master node) and worker-node(where executors are get created and processed), so basically two types of space is required by the spark program,so if you want to set driver memory then when start spark-shell .

spark-shell --driver-memory "your value" and to set executor memory : spark-shell --executor-memory "your value"

then I think you are good to go with the desired value of the memory that you want your spark-shell to use.

참고 URL : https://stackoverflow.com/questions/26562033/how-to-set-apache-spark-executor-memory

반응형