如何在 spark-submit 中使用 --num-executors 选项?
How to use --num-executors option with spark-submit?
我正在尝试覆盖 num-executors
等 spark 属性,同时通过 spark-submit 提交申请,如下所示:
spark-submit --class WC.WordCount \
--num-executors 8 \
--executor-cores 5 \
--executor-memory 3584M \
...../<myjar>.jar \
/public/blahblahblah /user/blahblah
但是它的 运行 默认执行器数量是 2。但是如果我添加
我可以覆盖属性
--master yarn
谁能解释一下为什么会这样?有趣的是,在我的应用程序代码中,我将 master 设置为 yarn-client:
val conf = new SparkConf()
.setAppName("wordcount")
.setMaster("yarn-client")
.set("spark.ui.port","56487")
val sc = new SparkContext(conf)
谁能解释一下选项 --master
的工作原理
如果您想要运行同一个应用程序与不同的主机或不同数量的内存。 Spark 允许您使用默认 SparkConf
来做到这一点。由于 您提到 SparkConf
的属性,这些属性在应用程序中具有最高优先级,最后检查属性优先级。
示例:
val sc = new SparkContext(new SparkConf())
然后,您可以在 运行 时提供配置值:
./bin/spark-submit \
--name "My app" \
--deploy-mode "client" \
--conf spark.ui.port=56487 \
--conf spark.master=yarn \ #alternate to --master
--conf spark.executor.memory=4g \ #alternate to --executor-memory
--conf "spark.executor.extraJavaOptions=-XX:+PrintGCDetails -XX:+PrintGCTimeStamps" \
--class WC.WordCount \
/<myjar>.jar \
/public/blahblahblah \
/user/blahblah
Properties precedence order (top one is more)
- Properties set directly on the
SparkConf
(in the code) take highest
precedence.
- Any values specified as flags or in the properties file will be passed
on to the application and merged with those specified through
SparkConf.
- then flags passed to
spark-submit
or spark-shell
like --master
etc
- then options in the
spark-defaults.conf
file.
A few configuration keys have been renamed since earlier versions of Spark; in such cases, the older key names are still accepted, but take lower precedence than any instance of the newer key.
I am trying to override spark properties such as num-executors while submitting the application by spark-submit as below
它将不工作(除非你在conf/spark-defaults.conf
文件或类似文件中覆盖spark.master
,所以你不必在命令中明确指定它线)。
原因是默认的Spark master是local[*]
,executor的个数恰好是一个,即driver。那只是本地部署环境。参见 Master URLs。
事实上,num-executors
非常依赖 YARN,正如您在帮助中看到的那样:
$ ./bin/spark-submit --help
...
YARN-only:
--num-executors NUM Number of executors to launch (Default: 2).
If dynamic allocation is enabled, the initial number of
executors will be at least NUM.
这就解释了为什么当您切换到 YARN 时它会起作用。它应该与 YARN 一起工作(无论部署模式如何,即客户端或集群,仅与驱动程序有关而不是执行程序)。
您可能想知道为什么它不适用于您代码中定义的 master。原因是为时已晚,因为当您使用 spark-submit 启动应用程序时,master 已经在启动时间分配。这正是您不应在代码中指定特定于部署环境的属性的原因:
- 不一定总是有效(看master的案例)
- 它要求每次配置更改都必须重新编译代码(这有点笨拙)
这就是为什么你应该总是使用 spark-submit
来提交你的 Spark 应用程序(除非你有理由不这样做,但你会知道为什么并且可以轻松解释它)。
我正在尝试覆盖 num-executors
等 spark 属性,同时通过 spark-submit 提交申请,如下所示:
spark-submit --class WC.WordCount \
--num-executors 8 \
--executor-cores 5 \
--executor-memory 3584M \
...../<myjar>.jar \
/public/blahblahblah /user/blahblah
但是它的 运行 默认执行器数量是 2。但是如果我添加
我可以覆盖属性--master yarn
谁能解释一下为什么会这样?有趣的是,在我的应用程序代码中,我将 master 设置为 yarn-client:
val conf = new SparkConf()
.setAppName("wordcount")
.setMaster("yarn-client")
.set("spark.ui.port","56487")
val sc = new SparkContext(conf)
谁能解释一下选项 --master
的工作原理
如果您想要运行同一个应用程序与不同的主机或不同数量的内存。 Spark 允许您使用默认 SparkConf
来做到这一点。由于 您提到 SparkConf
的属性,这些属性在应用程序中具有最高优先级,最后检查属性优先级。
示例:
val sc = new SparkContext(new SparkConf())
然后,您可以在 运行 时提供配置值:
./bin/spark-submit \
--name "My app" \
--deploy-mode "client" \
--conf spark.ui.port=56487 \
--conf spark.master=yarn \ #alternate to --master
--conf spark.executor.memory=4g \ #alternate to --executor-memory
--conf "spark.executor.extraJavaOptions=-XX:+PrintGCDetails -XX:+PrintGCTimeStamps" \
--class WC.WordCount \
/<myjar>.jar \
/public/blahblahblah \
/user/blahblah
Properties precedence order (top one is more)
- Properties set directly on the
SparkConf
(in the code) take highest precedence.- Any values specified as flags or in the properties file will be passed on to the application and merged with those specified through SparkConf.
- then flags passed to
spark-submit
orspark-shell
like--master
etc- then options in the
spark-defaults.conf
file.A few configuration keys have been renamed since earlier versions of Spark; in such cases, the older key names are still accepted, but take lower precedence than any instance of the newer key.
I am trying to override spark properties such as num-executors while submitting the application by spark-submit as below
它将不工作(除非你在conf/spark-defaults.conf
文件或类似文件中覆盖spark.master
,所以你不必在命令中明确指定它线)。
原因是默认的Spark master是local[*]
,executor的个数恰好是一个,即driver。那只是本地部署环境。参见 Master URLs。
事实上,num-executors
非常依赖 YARN,正如您在帮助中看到的那样:
$ ./bin/spark-submit --help
...
YARN-only:
--num-executors NUM Number of executors to launch (Default: 2).
If dynamic allocation is enabled, the initial number of
executors will be at least NUM.
这就解释了为什么当您切换到 YARN 时它会起作用。它应该与 YARN 一起工作(无论部署模式如何,即客户端或集群,仅与驱动程序有关而不是执行程序)。
您可能想知道为什么它不适用于您代码中定义的 master。原因是为时已晚,因为当您使用 spark-submit 启动应用程序时,master 已经在启动时间分配。这正是您不应在代码中指定特定于部署环境的属性的原因:
- 不一定总是有效(看master的案例)
- 它要求每次配置更改都必须重新编译代码(这有点笨拙)
这就是为什么你应该总是使用 spark-submit
来提交你的 Spark 应用程序(除非你有理由不这样做,但你会知道为什么并且可以轻松解释它)。