2016-07-29 107 views
5

我需要使用這個參數,所以我怎樣才能得到工人的數量? 與Scala一樣,我可以撥打sc.getExecutorMemoryStatus以獲得可用的工作人員數量。但在PySpark中,似乎沒有暴露的API來獲取這個數字。如何獲取PySpark中工作者(執行者)的數量?

+2

我不認爲這個問題是另一個重複。我想知道有多少執行者可以在驅動程序中使用,甚至在創建任何rdds之前,在Mesos上運行。很煩人,但我最終解析了ui:import pandas作爲pd df = pd.read_html(「http:// localhost:4040/executors」)[1] len(df [df ['Executor ID']! ='driver']) – MarkNS

+0

快速回答,獲取核心數:sc._jsc.sc()。getExecutorMemoryStatus()。size() – OronNavon

回答

12

在scala中,getExecutorStorageStatusgetExecutorMemoryStatus都返回包括驅動程序在內的執行程序的數量。 像例如以下代碼段

/** 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 
     } 

But In python api it was not implemented

answer @DanielDarabos也證實了這一點。

但是,我不是pyspark的專家。你可以嘗試一些相當於這個python的東西...

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

對不起,我遲到了,但在我的Pyspark中,它顯示「SparkContext對象有沒有屬性getConf「 –

+0

我的意思是在你嘗試python等效語法。不是因爲它... –

+0

我認爲它就像這個logger.info(sparkContext.getConf.getAll.mkString(「\ n」))將打印出所有參數,你可以找到執行人數以及 –