Spark参数设置的方式

可以通过以下几种方式设置:

1)bin/spark-submit 可以直接读取conf/spark-defaults.conf文件

每一行为一个key和value
spark.master            spark://5.6.7.8:7077
spark.executor.memory   4g
spark.eventLog.enabled  true
spark.serializer        org.apache.spark.serializer.KryoSerializer
Spark之参数介绍

2)在spark-submit or spark-shell运行时指定参数

2.1)--conf     PROP=VALUE     固定的spark配置属性

./bin/spark-submit --name "My app" --master local[4] --conf spark.eventLog.enabled=false
  --conf "spark.executor.extraJavaOptions=-XX:+PrintGCDetails -XX:+PrintGCTimeStamps" myApp.jar

2.2)--properties-file     FILE     加载额外属性的文件

如果要使用--properties-file的话,在--properties-file中定义的属性就不必要在spark-sumbit中再定义了,比如在conf/spark-defaults.conf 定义了spark.master,就可以不使用--master了。
关于Spark属性的优先权为:SparkConf方式 > 命令行参数方式 >文件配置方式,最终的参数为3者的merge

3)编码方式:SparkConf中指定

3.1)硬编码方式:

var conf =new SparkConf()
conf.set("spark.eventLog.enabled","true")
val sc = new SparkContext()
备注:可以创建空conf

3.2)spark-submit ... --application-arguments方式:

./bin/spark-submit \
  --class <main-class>
  --master <master-url> \
  --deploy-mode <deploy-mode> \
  --conf <key>=<value> \
  ... # other options
  <application-jar> \
  [application-arguments]

备注:application-arguments可以指定具体的参数值,也可以指定具体的配置文件。


参考:

https://blog.csdn.net/hjw199089/article/details/72716607
https://www.jianshu.com/p/9b243c0a7410
http://blog.javachen.com/2015/06/07/spark-configuration.html

posted @ 2018-07-31 09:35  cctext  阅读(6507)  评论(0编辑  收藏  举报