2016-09-29 76 views

回答

1

Apache Spark中有一个类,即ExecutorInfo,它具有返回执行主机IP的方法executorHost()。

1

您应该使用SparkListener抽象类并拦截两个执行程序特定事件 - SparkListenerExecutorAddedSparkListenerExecutorRemoved

override def onExecutorAdded(executorAdded: SparkListenerExecutorAdded): Unit = { 
    val execId = executorAdded.executorId 
    val host = executorAdded.executorInfo.executorHost 
    executors += (execId -> host) 
    println(s">>> executor id=$execId added on host=$host") 
} 

override def onExecutorRemoved(executorRemoved: SparkListenerExecutorRemoved): Unit = { 
    val execId = executorRemoved.executorId 
    val host = executors remove execId getOrElse "Host unknown" 
    println(s">>> executor id=$execId removed from host=$host") 
} 

整个工作项目在我的Spark Executor Monitor Project

+0

我也试过这个选项,但我需要提供这个执行程序列表来完成RDD的一些转换,比如将分区映射到执行程序(粘滞分区)。但是看起来像这样在调用sc.start()时不会被调用,但它也可能是后者。因此,在调用dstream上的某些函数来转换RDD之前,无法获取列表。谢谢你的时间 ! –

+0

如果您需要在*动作(不知道分配给您的应用程序的执行程序)之前请求特定的执行程序,那么您必须开发一个定制的RDD,该列表将作为“preferredLocation”列表。这需要开发你自己定制的'DStream',这是可行的。你真的想达到什么目的?什么是用例? –

相关问题