使用 sparklyr 和 R 获取活跃的 spark 执行器的数量

Get number of active spark executors with sparklyr and R

当通过 sparklyr 启动 spark 集群时,我注意到所有执行程序联机可能需要 10-60 秒。

现在我正在使用 Sys.sleep(60) 让他们有时间上线,但有时需要更长的时间,有时比​​这更短。我想要一种程序化的方式来调整这个时间差异,类似于 关于 Python。所以我想我想通过 sparklyr 传递 getExecutorMemoryStatus,但我不确定该怎么做。

要查看我所看到的,运行 以下代码启动 yarn-client spark 连接,并检查 Yarn UI。在事件时间轴中,我们可以看到每个执行者上线的时间。

spark_config <- spark_config()
spark_config$spark.executor.memory <- "11G"
spark_config$`sparklyr.shell.driver-memory` <- "11G"
spark_config$spark.dynamicAllocation.enabled <- FALSE
spark_config$`spark.yarn.executor.memoryOverhead` <- "1G"
spark_config$spark.executor.instances <- 32

sc <- spark_connect(master = "yarn-client", config = spark_config)

So I think I want to pass getExecutorMemoryStatus via sparklyr, but I'm not sure how to do this.

您必须检索 SparkContext 对象:

sc <- spark_connect(...)

spark_context(sc) %>%
  ...

然后invoke方法:

 ... %>% invoke("getExecutorMemoryStatus")

一起:

spark_context(sc) %>% 
  invoke("getExecutorMemoryStatus") %>% 
  names()

应该给你一个活跃的执行者列表。