[Spark] Dynamic Allocation 사용
Spark 3.4.1 사용중이고 리소스매니저는 Yarn을 사용중이다.
Dynamic allocation은 Executor들에게만 적용된다.
아래 설정들을 spark-defaults.conf에 해줘야 한다.
만약 spark-thrift-sparkconf.conf에 해주면 Thrift server통해서 실행되는 Spark Job에만 적용된다.
공식문서 (3.4.1)
https://archive.apache.org/dist/spark/docs/3.4.1/configuration.html#dynamic-allocation
https://archive.apache.org/dist/spark/docs/3.4.1/job-scheduling.html
Dynamic Allocation을 설정하는 방법은 두 가지가 있다.
There are two ways for using this feature.
First, your application must set both spark.dynamicAllocation.enabled and spark.dynamicAllocation.shuffleTracking.enabled to true.
Second, your application must set both spark.dynamicAllocation.enabled and spark.shuffle.service.enabled to true after you set up an external shuffle service on each worker node in the same cluster.
현재 아래 방법은 두 번째 방법을 적용하는 과정이다.
Yarn에서 외부 셔플 설정하는 과정이 번거로우면 그냥 첫 번째 방법을 추천한다.
spark.dynamicAllocation.shuffleTracking.enabled = true (첫 번째 방법 설정값)
* spark-defaults.conf
spark.dynamicAllocation.enabled = true
spark.shuffle.service.enabled = true
( The purpose of the shuffle tracking or the external shuffle service is to allow executors to be removed without deleting shuffle files written by them )
spark.dynamicAllocation.minExecutors = 1
spark.dynamicAllocation.initialExecutors = 1
spark.dynamicAllocation.maxExecutors = 10 (Executor 개수를 10개를 넘지 못하게 한다.)
Yarn에서 Externl Shuffle Service를 설정하는 방법은 다음과 같다.
이미 설정되어 있으므로 설정값들만 확인한다.
1. jar파일은 다음을 사용중 spark-3.4.1-100-yarn-shuffle.jar
2. 현재 각 Nodemanager설치된 서버의 다음 경로에 위치해있다.
/usr/bigdata/spark3/yarn
3. 아래 설정 (아래에서 spark3_shuffle 참고)
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle,spark_shuffle,,spark3_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.mapreduce_shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.spark3_shuffle.class</name>
<value>org.apache.spark.network.yarn.YarnShuffleService</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.spark3_shuffle.classpath</name>
<value>/usr/bigdata/spark3/yarn/*:/usr/bigdata/spark3/conf/yarn</value>
</property>
<property>
<name>yarn.nodemanager.aux-services.spark_shuffle.class</name>
<value>org.apache.spark.network.yarn.YarnShuffleService</value>
</property>
Spark3 재기동해준다.
이제 정상적으로 잘 실행되는지 확인한다.
처음에 1개만 생성됐는데 아래처럼 잡의 부하에 따라 여러 개 생성된다.
다시 부하가 줄어들면 아래처럼 1개만 남고 나머지 익스큐터들 사라진다.