Data platformProcessingApache SparkSparkContext, SparkSession & State

SparkContext, SparkSession & State

SparkContext, SparkSession, SharedState, SessionState và temp view boundary.

Câu hỏi

SparkContextSparkSession khác nhau thế nào, và state nằm ở đâu?

Mental model

Có thể nghĩ đơn giản:

SparkContext
  -> connection tới cluster/executors
  -> runtime-level object của application

SparkSession
  -> SQL/DataFrame entrypoint
  -> catalog/config/session state
  -> có thể có nhiều session quanh một SparkContext

Trong Spark SQL còn có hai lớp state dễ nhầm:

SharedState
  -> state dùng chung trong một SparkContext/application
  -> ví dụ external catalog/cache/global temp view manager

SessionState
  -> state riêng của từng SparkSession
  -> ví dụ SQLConf, temp views, parser/analyzer/session catalog view

Temp view là ví dụ dễ thấy

local temp view
  -> thuộc SparkSession hiện tại

global temp view
  -> thuộc shared global_temp database trong application

Nếu hai notebook dùng chung SparkContext nhưng khác SparkSession, câu hỏi là: cái gì được share, cái gì tách riêng?

Vì sao liên quan Databricks Runtime

Databricks Dedicated/interactive runtime có thể làm mình thấy nhiều notebook attach vào cùng compute/driver. Muốn hiểu chuyện này phải phân biệt:

cluster/runtime shared state
SparkContext shared state
SparkSession state
notebook/language REPL state
command-local context

Đây là nền để đọc DriverCorral, DriverLocal, REPL/session mapping và databricks-interactive-runtime.mdx.

Đọc tiếp

On this page