通過spark-submit會固定占用一占的資源灯蝴,有什么辦法颜骤,在任務(wù)不運作的時候?qū)①Y源釋放柔袁,讓其它任務(wù)使用呢呆躲,yarn新版本默認(rèn)已經(jīng)支持了,我們使用的是HDP捶索。
版本如下
配置
HDP里面已經(jīng)默認(rèn)支持spark動態(tài)資源釋配置
代碼配置
val sparkConf = new SparkConf()
.set("spark.shuffle.service.enabled", "true")
.set("spark.dynamicAllocation.enabled", "true")
.set("spark.dynamicAllocation.minExecutors", "1") //最少占用1個Executor
.set("spark.dynamicAllocation.initialExecutors", "1") //默認(rèn)初始化一個Executor
.set("spark.dynamicAllocation.maxExecutors", "6") //最多占用6個Executor
.set("spark.dynamicAllocation.executorIdleTimeout", "60") //executor閑置時間
.set("spark.dynamicAllocation.cachedExecutorIdleTimeout", "60") //cache閑置時間
.set("spark.executor.cores", "3")//使用的vcore
// .setMaster("local[12]")
.setAppName("Spark DynamicRelease")
val spark: SparkSession = SparkSession
.builder
.config(sparkConf)
.getOrCreate()
注意事項
如果spark計算當(dāng)中使用了rdd.cache插掂,不加下面的配置,動態(tài)資源不會釋放
.set("spark.dynamicAllocation.cachedExecutorIdleTimeout", "60")