Spark - 资源动态释放

> 通过spark-submit会固定占用一占的资源,有什么办法,在任务不运作的时候将资源释放,让其它任务使用呢,yarn新版本默认已经支持了,我们使用的是HDP。

## 版本如下

![](https://upload-images.jianshu.io/upload_images/9028759-35c1bf0606261dc5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

## 配置

1. HDP里面已经默认支持spark动态资源释配置

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,不加下面的配置,动态资源不会释放

```

.set("spark.dynamicAllocation.cachedExecutorIdleTimeout", "60")

```

---

![](https://upload-images.jianshu.io/upload_images/9028759-07315bb8dadcd082.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • > 通过spark-submit会固定占用一占的资源,有什么办法,在任务不运作的时候将资源释放,让其它任务使用呢,...
    kikiki4阅读 162评论 0 1
  • > 通过spark-submit会固定占用一占的资源,有什么办法,在任务不运作的时候将资源释放,让其它任务使用呢,...
    kikiki4阅读 90评论 0 1
  • > 通过spark-submit会固定占用一占的资源,有什么办法,在任务不运作的时候将资源释放,让其它任务使用呢,...
    kikiki4阅读 96评论 0 2
  • > 通过spark-submit会固定占用一占的资源,有什么办法,在任务不运作的时候将资源释放,让其它任务使用呢,...
    kikiki5阅读 251评论 0 1
  • > 通过spark-submit会固定占用一占的资源,有什么办法,在任务不运作的时候将资源释放,让其它任务使用呢,...
    kikiki4阅读 120评论 0 3