Spark 介面(Spark UI)

Python Spark SQL 入門

Mark Plutowski

Data Scientist

使用 Spark UI 檢視執行情形

  • Spark Task:在單一 CPU 上執行的最小執行單位。

  • Spark Stage:一組並行執行相同計算的任務,通常各自處理資料的不同子集。

  • Spark Job:由 action 觸發的計算,會切分為一個或多個 stage。

Python Spark SQL 入門

如何找到 Spark UI

  1. http://[DRIVER_HOST]:4040
  2. http://[DRIVER_HOST]:4041
  3. http://[DRIVER_HOST]:4042
  4. http://[DRIVER_HOST]:4043
    ...
Python Spark SQL 入門

Python Spark SQL 入門

Python Spark SQL 入門

Python Spark SQL 入門

Spark Catalog 操作

  • spark.catalog.cacheTable('table1')
  • spark.catalog.uncacheTable('table1')
  • spark.catalog.isCached('table1')
  • spark.catalog.dropTempView('table1')
Python Spark SQL 入門

Spark Catalog

spark.catalog.listTables()
[Table(name='text', database=None, description=None, tableType='TEMPORARY', isTemporary=True)]
Python Spark SQL 入門

Python Spark SQL 入門

Python Spark SQL 入門

Spark UI「Storage」分頁

顯示資料分割區的位置:

  • 在記憶體中,
  • 或在磁碟上,
  • 分散於叢集各節點,
  • 以及某個時間點的快照。
Python Spark SQL 入門

Spark UI「SQL」分頁

query3agg = """
SELECT w1, w2, w3, COUNT(*) as count FROM (
   SELECT 
   word AS w1,
   LEAD(word,1) OVER(PARTITION BY part ORDER BY id ) AS w2,
   LEAD(word,2) OVER(PARTITION BY part ORDER BY id ) AS w3
   FROM df
)
GROUP BY w1, w2, w3 
ORDER BY count DESC
""" 

spark.sql(query3agg).show()
Python Spark SQL 入門

Python Spark SQL 入門

Python Spark SQL 入門

Python Spark SQL 入門

Python Spark SQL 入門

一起來練習吧!

Python Spark SQL 入門

Preparing Video For Download...