首页 > 代码库 > Spark-Sql On YARN自动调整Executor数配置

Spark-Sql On YARN自动调整Executor数配置

最新的Spark 1.2版本支持为Spark On YARN模式的Spark Application根据Task自动调整Executor数,要启用该功能,需做以下操作:

一:

在所有的NodeManager中,修改yarn-site.xml,为yarn.nodemanager.aux-services添加spark_shuffle值,设置yarn.nodemanager.aux-services.spark_shuffle.class值为org.apache.spark.network.yarn.YarnShuffleService,如下:

   
  1. <property>
  2. <name>yarn.nodemanager.aux-services</name>
  3. <value>mapreduce_shuffle,spark_shuffle<alue>
  4. </property>
  5. <property>
  6. <name>yarn.nodemanager.aux-services.spark_shuffle.class</name>
  7. <value>org.apache.spark.network.yarn.YarnShuffleService</value>
  8. </property>

二:

将 $SPARK_HOME/lib/spark-1.2.0-yarn-shuffle.jar文件拷贝到hadoop-yarn/lib目录下(即yarn的库目录)


三:

配置 $SPARK_HOME/conf/spark-default.xml,添加以下两项

   
  1. spark.dynamicAllocation.minExecutors 1 #最小Executor数
  2. spark.dynamicAllocation.maxExecutors 100 #最大Executor数

四:

执行时开启自动调整Executor数开关,以spark-sql yarn client模式为例:

   
  1. spark-sql \
  2. --master yarn \
  3. --deploy-mode client \
  4. --conf spark.shuffle.service.enabled=true \
  5. --conf spark.dynamicAllocation.enabled=true \
  6. -e "SELECT COUNT(*) FROM xx"

对于使用spark-submit也是一样:

   
  1. spark-submit \
  2. --class SySpark.SqlOnSpark \
  3. --master yarn-client \
  4. --conf spark.shuffle.service.enabled=true \
  5. --conf spark.dynamicAllocation.enabled=true \
  6. /data/jars/SqlOnSpark.jar \
  7. "SELECT COUNT(*) FROM xx"

Spark-Sql On YARN自动调整Executor数配置