Apache spark 如何了解Spark应用程序的executor IP?
我想在运行时获得执行器的所有IP,我应该使用Spark中的哪个API?或者任何其他方法在运行时获取IP?Apache Spark中有一个类,即ExecuteInfo,它有一个方法ExecuteHost(),返回执行器主机IP。您应该使用抽象类并截获两个特定于执行器的事件-Apache spark 如何了解Spark应用程序的executor IP?,apache-spark,Apache Spark,我想在运行时获得执行器的所有IP,我应该使用Spark中的哪个API?或者任何其他方法在运行时获取IP?Apache Spark中有一个类,即ExecuteInfo,它有一个方法ExecuteHost(),返回执行器主机IP。您应该使用抽象类并截获两个特定于执行器的事件-SparkListenerExecutorAdded和SparkListenerExecutorRemoved 覆盖def onExecutorAdded(executorAdded:sparklistenereexecutor
SparkListenerExecutorAdded
和SparkListenerExecutorRemoved
覆盖def onExecutorAdded(executorAdded:sparklistenereexecutoradded):单位={
val execId=executorAdded.executorId
val host=executorAdded.executorInfo.executorHost
执行器+=(execId->host)
println(s“>>>在主机上添加的执行器id=$execId=$host”)
}
覆盖def ONEXECUTOR删除(已删除执行器:SparkListenerExecutorRemoved):单位={
val execId=executorRemoved.executorId
val host=执行者删除execId getOrElse“主机未知”
println(s“>>>executor id=$execId已从主机中删除=$host”)
}
整个工作项目都在我的中。我也尝试了这个选项,不过我需要提供这个执行者列表来对RDD进行一些转换,比如将分区映射到执行者(粘性分区)。但是看起来在调用sc.start()时不会调用它,但也可能是后者。因此,在调用数据流上的某些函数来转换RDD之前,无法获取列表。谢谢你的时间!如果您需要在操作之前请求特定的执行者(不知道分配给您的应用程序的执行者),您必须开发一个自定义RDD,该RDD的列表为
preferredLocation
。这需要开发自己的定制DStream
,这是可行的。你到底想达到什么目的?用例是什么?