首先,我读了这篇文章,其中说如果未明确设置
spark.dynamicAllocation.maxExecutors
,则num-executors
的值将等于spark.dynamicAllocation.maxExecutors
。然而,从本文的以下部分来看,它说“--num-executors
或spark.executor.instances
充当执行器的最小数量,默认值为2”,这让我很困惑。
我的第一个问题是
--num-executors
在Spark 2.x或更高版本中的用法是什么?它是否像一个在动态分配之前有用的过时选项?当引入dynamicAllocation时,--num-executors
和--max-executors
的行为更像是spark.dynamicAllocation.*
的一些默认值?
--conf spark.dynamicAllocation.maxExecutors
和--max-executor
有什么区别?后者的作用就像前者的别名吗?
同时,文章并没有提及
num-executors
和spark.dynamicAllocation.initialExecutors
之间的关系。所以我做了一个实验,我发送以下参数:
--conf spark.dynamicAllocation.minExecutors=2 --conf spark.dynamicAllocation.maxExecutors=20 --conf spark.dynamicAllocation.enabled=true --conf spark.dynamicAllocation.initialExecutors=3 --conf spark.dynamicAllocation.maxExecutors=10 --num-executors 0 --driver-memory 1g --executor-memory 1g --executor-cores 2
结果发现,一开始分配了3个executor(对应
initialExecutors
),然后减少到2个(对应minExecutors
),看起来--num-executors
在这里没什么用。但是,文章中说“-num-executors 或spark.executor.instances 充当执行器的最小数量”,所以现在存在矛盾。
num-executors
和spark.dynamicAllocation.initialExecutors
之间的关系是什么,spark.dynamicAllocation.initialExecutors
先于num-executors
吗?从文档中,我发现当num-executors
设置得大于spark.dynamicAllocation.initialExecutors
时,它将覆盖spark.dynamicAllocation.initialExecutors
。您的第一篇文章来自 Qubole 的开发人员指南,它不一定反映 Apache Spark 的默认行为。
回答您的问题:
num-executors
不一定会过时,如果您使用单独的进程或命令设置了动态分配,则当动态分配因任何原因关闭时,num-executors
可以充当正确分配的保障。因此,我通常将 num-executors
设置为等于 spark.dynamicAllocation.maxExecutors
。max-executors
,但我会假设它是一个别名,其中较小者和 spark.dynamicAllocation.maxExecutors
是设置的最大值(如果两者都指定了),按照 Spark 的典型逻辑。最好只使用spark.dynamicAllocation.maxExecutors
。num-executors
的行为与 spark.dynamicAllocation.initialExecutors
而不是 spark.dynamicAllocation.minExecutors
。初始执行器设置为 spark.dynamicAllocation.initialExecutors
、spark.dynamicAllocation.minExecutors
和 spark.executor.instances
中的最大值(来自 源代码)。