如何使用动态资源分配执行spark程序?

7ajki6be  于 2021-05-27  发布在  Spark
关注(0)|答案(2)|浏览(467)

我使用spark summit命令执行spark作业,参数如下:

spark-submit --master yarn-cluster --driver-cores 2 \
 --driver-memory 2G --num-executors 10 \
 --executor-cores 5 --executor-memory 2G \
 --class com.spark.sql.jdbc.SparkDFtoOracle2 \
 Spark-hive-sql-Dataframe-0.0.1-SNAPSHOT-jar-with-dependencies.jar

现在我想使用spark的动态资源分配来执行相同的程序。在执行spark程序时,请您帮助使用动态资源分配。

u5rb5r59

u5rb5r591#

我刚刚用spark的动态资源分配做了一个小演示。代码在我的github上。具体来说,演示版就在这个版本中。

8yoxcaq7

8yoxcaq72#

在spark动态分配中 spark.dynamicAllocation.enabled 需要设置为 true 因为它是 false 默认情况下。
这需要 spark.shuffle.service.enabled 设置为 true ,因为Spark应用在Yarn上运行。选中此链接可在yarn中的每个nodemanager上启动shuffle服务。
以下配置也与此相关:

spark.dynamicAllocation.minExecutors, 
spark.dynamicAllocation.maxExecutors, and 
spark.dynamicAllocation.initialExecutors

这些选项可以配置为以3种方式激发应用程序
1从spark提交 --conf <prop_name>=<prop_value> ```
spark-submit --master yarn-cluster
--driver-cores 2
--driver-memory 2G
--num-executors 10
--executor-cores 5
--executor-memory 2G
--conf spark.dynamicAllocation.minExecutors=5
--conf spark.dynamicAllocation.maxExecutors=30
--conf spark.dynamicAllocation.initialExecutors=10 \ # same as --num-executors 10
--class com.spark.sql.jdbc.SparkDFtoOracle2
Spark-hive-sql-Dataframe-0.0.1-SNAPSHOT-jar-with-dependencies.jar

2内部Spark程序 `SparkConf` 在中设置属性 `SparkConf` 然后创建 `SparkSession` 或者 `SparkContext` 有了它

val conf: SparkConf = new SparkConf()
conf.set("spark.dynamicAllocation.minExecutors", "5");
conf.set("spark.dynamicAllocation.maxExecutors", "30");
conf.set("spark.dynamicAllocation.initialExecutors", "10");
.....

三。 `spark-defaults.conf` 通常位于 `$SPARK_HOME/conf/` 将相同的配置放入 `spark-defaults.conf` 如果没有从命令行和代码传递任何配置,则应用于所有spark应用程序。
spark-动态分配会议

相关问题