Rom*_*nko 22 java scala cluster-computing hadoop-yarn apache-spark
我如何配置Java(或Scala)代码量的执行程序有SparkConfig和SparkContext?我经常看到2个执行者.看起来spark.default.parallelism不起作用,是关于不同的东西.
我只需要将执行程序的数量设置为等于群集大小,但总是只有2个.我知道我的簇大小.如果这很重要,我会在YARN上运行.
小智 22
您也可以通过在SparkConf对象上设置参数"spark.executor.instances"和"spark.executor.cores"以编程方式执行此操作.
例:
SparkConf conf = new SparkConf()
// 4 workers
.set("spark.executor.instances", "4")
// 5 cores on each workers
.set("spark.executor.cores", "5");
Run Code Online (Sandbox Code Playgroud)
第二个参数仅适用于YARN和独立模式.它允许应用程序在同一个worker上运行多个执行程序,前提是该worker上有足够的内核.
Rom*_*nko 21
好的,我知道了.执行程序的数量实际上不是Spark属性本身,而是用于在YARN上放置作业的驱动程序.因此我使用SparkSubmit类作为驱动程序,它具有适当的--num-executors参数,这正是我需要的.
更新:
对于某些工作,我不再遵循SparkSubmit方法了.我不能主要用于Spark作业只是应用程序组件之一的应用程序(甚至是可选的).对于这些情况,我使用spark-defaults.conf附加到群集配置和其中的spark.executor.instances属性.这种方法更加通用,允许我根据集群(开发人员工作站,登台,生产)正确平衡资源.
我们在实验室中使用 HDFS 上的数据在 Yarn 上运行 Spark 时遇到了类似的问题,但无论我尝试上述哪种解决方案,我都无法将 Spark 执行器的数量增加到超过两个。
结果发现数据集太小(小于 128 MB 的 hdfs 块大小),并且由于 hadoop 的默认数据复制启发式,仅存在于两个数据节点(集群中 1 个主节点、7 个数据节点)上。
一旦我和我的实验室伙伴有了更多的文件(和更大的文件)并且数据分布在所有节点上,我们就可以设置 Spark 执行器的数量,并最终看到--num-executors完成时间和完成时间之间的反比关系。
希望这可以帮助处于类似情况的其他人。
小智 5
在Spark 2.0+版本中
使用spark会话变量动态设置执行程序的数量(从程序内部)
spark.conf.set("spark.executor.instances", 4)
spark.conf.set("spark.executor.cores", 4)
In above case maximum 16 tasks will be executed at any given time.
other option is dynamic allocation of executors as below -
spark.conf.set("spark.dynamicAllocation.enabled", "true")
spark.conf.set("spark.executor.cores", 4)
spark.conf.set("spark.dynamicAllocation.minExecutors","1")
spark.conf.set("spark.dynamicAllocation.maxExecutors","5")
This was you can let spark decide on allocating number of executors based on processing and memory requirements for running job.
I feel second option works better that first option and is widely used.
Hope this will help.
| 归档时间: |
|
| 查看次数: |
35799 次 |
| 最近记录: |