Sub topic 4
Turning Photon on
This chapter shows how to enable Photon on Databricks compute and how to confirm it is active. It assumes you can create clusters or SQL warehouses, know basic Spark terms such as stages and tasks, and have read the previous chapter on what Photon accelerates.
Where Photon is already on
Photon is a native, vectorized execution engine. You do not install it. You select it as a property of the compute.
- SQL warehouses: Photon is enabled by default on Databricks SQL warehouses. Serverless and pro warehouses use it, and you cannot switch it off. Check the compute type before you look for a setting.
- Serverless compute for notebooks and jobs: Photon is part of the managed runtime.
- All-purpose and job clusters: Photon is a choice you make. Some runtime versions and workspace defaults turn it on, so verify instead of assuming.
Enable Photon in the UI
- Open Compute and select Create compute.
- Choose a supported Databricks Runtime version.
- Tick Use Photon Acceleration.
- Pick a supported instance type and create the cluster.
Photon needs a runtime and instance family that support it. If the checkbox is missing or disabled, change the runtime version or node type first.
Enable Photon with the Clusters API
In the API and in infrastructure-as-code tools, the setting is the runtime_engine field. The value PHOTON selects Photon. The value STANDARD selects the regular Spark engine.
{
"cluster_name": "photon-demo",
"spark_version": "<a Databricks Runtime version string>",
"node_type_id": "<a node type available in your workspace>",
"num_workers": 2,
"runtime_engine": "PHOTON"
}Replace both placeholders with values that are valid in your workspace. A runtime string or node type that does not exist makes the request fail.
Confirm that Photon is active
Setting the flag does not prove a query used Photon. Check in two places.
- Cluster details: the compute page shows that Photon acceleration is on.
- Query plan: run
EXPLAIN FORMATTEDand look for operators whose names start withPhoton, such asPhotonScan,PhotonGroupingAggorPhotonBroadcastHashJoin. Operators without that prefix ran in standard Spark.
Common errors
- Assuming Photon is on for every cluster. Older or copied cluster definitions may still say
STANDARD. - Expecting every operator to run in Photon. A Photon cluster can run part of a query in Spark. The chapter after this one explains when that happens.
- Testing on tiny data. Photon helps most on large scans, joins and aggregations. A query over a few thousand rows shows little change.
- Comparing runs unfairly. Cached data and different cluster sizes distort results. Benchmarking gets its own chapter.
Exercise
A teammate's job cluster definition contains "runtime_engine": "STANDARD". They say Photon is on because the workspace admin enabled it. What do you change, and how do you confirm the change worked?
Show answer
Change the value to "PHOTON" (after checking that the runtime version and node type support it). Then run EXPLAIN FORMATTED on a representative query and look for operators with the Photon prefix, such as PhotonScan or PhotonGroupingAgg. Seeing those operators confirms Photon ran them.