2017-09-01 168 views
1

我需要一些幫助來了解Spark如何決定分區的數量以及它們在執行器中的處理方式,我很抱歉這個問題,因爲我知道這是一個重複的問題,但即使在閱讀了很多文章之後,我仍然無法理解我正在將我現在正在使用的一個真實生活用例,以及我的spark submit config和cluster config。Apache Spark如何計算分區以及如何在執行器中處理分區

我的硬件配置:

3 Node machine with total Vcores=30 and Total Memory=320 GB.

spark-submit config: 

spark-submit \ 
--verbose \ 
--master yarn \ 
--deploy-mode cluster \ 
--num-executors 1 \ 
--executor-memory 3g \ 
--executor-cores 2 \ 
--conf spark.yarn.maxAppAttempts=1 \ 
--conf spark.yarn.am.attemptFailuresValidityInterval=1h \ 
--conf spark.driver.memory=1000m \ 
--conf spark.speculation=true \ 

我從MySQL數據庫使用火花數據幀JDBC API閱讀:

val jdbcTable= sqlContext.read.format("jdbc").options(
      Map(
       "url" -> jdcbUrl, 
       "driver" -> "net.sourceforge.jtds.jdbc.Driver", 
       "dbtable" -> 
       s"(SELECT * FROM SOMETHING WHERE COLUMN > ${lastExtractUnixTime}) as t")) 
      .load 

通過jdbcTable數據框創建的分區的總數爲200

問題:

  1. 火花是怎麼產生的200分區,這是默認設置嗎?

  2. 因爲我只有1個執行程序嗎200分區是在單個執行程序中並行處理還是一次處理一個分區?

  3. executor-cores是否用於處理每個分區中配置併發的任務,即2(在我的情況下)?

回答

0
  • 因爲它是寫現在星火will use 1 partition only
  • 如果你看到200個的分區意味着:

    • 有後續的洗牌(交換)代碼未顯示。
    • 您使用spark.sql.shuffle.partitions的默認值。
  • 並行性將取決於執行計劃和分配的資源。它不會高於min(number-partitions, spark-cores)。如果有一個執行程序,它將由集羣管理器分配給該執行程序的線程數。