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