2016-09-29 75 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',這是可行的。你真的想達到什麼目的?什麼是用例? –

相關問題