開始使用免費開始

比較 broadcast 與一般 join

你已經建立了兩種 join:一般與 broadcast。現在你的主管想知道,使用 Spark 最佳化之後效能提升多少。若結果值得期待,你將有更多機會按需求微調 Spark 設定。

你的 DataFrame normal_dfbroadcast_df 已可使用。

本練習屬於課程

使用 PySpark 清理資料

檢視課程

練習說明

  • 在一般的 DataFrame 上執行 .count()
  • 在 broadcast 的 DataFrame 上執行 .count()
  • 列印兩個 DataFrame 的筆數與耗時,並記錄任何差異。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

start_time = time.time()
# Count the number of rows in the normal DataFrame
normal_count = ____
normal_duration = time.time() - start_time

start_time = time.time()
# Count the number of rows in the broadcast DataFrame
broadcast_count = ____
broadcast_duration = time.time() - start_time

# Print the counts and the duration of the tests
print("Normal count:\t\t%d\tduration: %f" % (normal_count, normal_duration))
print("Broadcast count:\t%d\tduration: %f" % (broadcast_count, broadcast_duration))
編輯並執行程式碼