【问题标题】:Spark - How many Executors and Cores are allocated to my spark jobSpark - 为我的 Spark 作业分配了多少执行器和核心
【发布时间】:2017-01-02 21:02:09
【问题描述】:

Spark 架构完全围绕执行器和核心的概念展开。我想看看在集群中运行的 Spark 应用程序实际上有多少个执行程序和内核运行。

我试图在我的应用程序中使用低于 sn-p 但没有运气。

val conf = new SparkConf().setAppName("ExecutorTestJob")
val sc = new SparkContext(conf)
conf.get("spark.executor.instances")
conf.get("spark.executor.cores")

有没有办法使用SparkContext Object 或SparkConf object 等获取这些值。

【问题讨论】:

  • 您可以在 Spark UI 中查看。转到 http://:4040 并按“Executors”选项卡。这因集群管理器而异。
  • 克里希纳,你能得到吗?随时提问
  • 你能测试吗?
  • 非常感谢@RamPrasad。它有很大帮助。尝试了不同大小的不同数据集,并能够获得执行者节点。
  • @KrishnaReddy 你可以使用history server

标签: python scala hadoop apache-spark executors


【解决方案1】:

Scala(程序化方式):

getExecutorStorageStatusgetExecutorMemoryStatus 都返回包括驱动程序在内的执行程序的数量。 就像下面的例子 sn-p。

/** Method that just returns the current active/registered executors
        * excluding the driver.
        * @param sc The spark context to retrieve registered executors.
        * @return a list of executors each in the form of host:port.
        */
       def currentActiveExecutors(sc: SparkContext): Seq[String] = {
         val allExecutors = sc.getExecutorMemoryStatus.map(_._1)
         val driverHost: String = sc.getConf.get("spark.driver.host")
         allExecutors.filter(! _.split(":")(0).equals(driverHost)).toList
       }

sc.getConf.getInt("spark.executor.instances", 1)

类似地获取所有属性并像下面这样打印,您也可以获得核心信息..

sc.getConf.getAll.mkString("\n")

sc.getConf.toDebugString

大多数spark.executor.cores 用于执行者spark.driver.cores 驱动程序应该有这个值。

Python:

Above methods getExecutorStorageStatus and getExecutorMemoryStatus, In python api were not implemented

编辑 但可以使用从 SparkSession 公开的 Py4J 绑定进行访问。

sc._jsc.sc().getExecutorMemoryStatus()

【讨论】:

  • 此时这是一个旧答案,但我想知道如何在 R 中使用 sparklyr 完成此操作。有什么建议吗?
  • 请询问关于 sparkyr 的另一个问题
  • 关于 python - 它似乎对我不起作用。我问了一个question,并为此提供了一个最小的例子。如果可以的话,我将不胜感激。
【解决方案2】:

这是获取核心数量的python示例(包括master的) def workername(): import socket return str(socket.gethostname()) anrdd=sc.parallelize(['','']) namesRDD = anrdd.flatMap(lambda e: (1,workername())) namesRDD.count()

【讨论】:

  • 这个 sn-p 只期望返回用于计算 flatmap 中的 lambda 的执行程序的数量(并且,也给出了一些更正:使用 countByKey 并交换常量1 和对方法的调用),这通常与分配给应用程序的执行者数量有很大不同。
【解决方案3】:

这是一个老问题,但这是我在 Spark 2.3.0 上解决这个问题的代码:

+ 414     executor_count = len(spark.sparkContext._jsc.sc().statusTracker().getExecutorInfos()) - 1
+ 415     cores_per_executor = int(spark.sparkContext.getConf().get('spark.executor.cores','1'))

【讨论】:

  • 谢谢,今天在 pyspark 2.4 上确认了这一点,它可以工作。
  • 无法确认第二个是否有效:这将始终在get() 函数中输出数字!示例:sc.getConf().get('anytexthere', "152") 将输出 152...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-02
相关资源
最近更新 更多