> 通過spark-submit會固定占用一占的資源垦搬,有什么辦法皮钠,在任務不運作的時候將資源釋放,讓其它任務使用呢典奉,yarn新版本默認已經(jīng)支持了躺翻,我們使用的是HDP。
## 版本如下

## 配置
1. HDP里面已經(jīng)默認支持spark動態(tài)資源釋配置
2. 代碼配置
```
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") //默認初始化一個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計算當中使用了rdd.cache卫玖,不加下面的配置公你,動態(tài)資源不會釋放
```
.set("spark.dynamicAllocation.cachedExecutorIdleTimeout", "60")
```
---
