Sub topic 4
Turning Photon on
This chapter shows how to enable Photon on Databricks compute, how to confirm it is active, and where it is already on by default. It assumes you know basic SQL, can create a cluster or SQL warehouse in a Databricks workspace, and have read the previous chapter on what Photon is and what it accelerates.
Where Photon is already on
Photon is a setting of the compute resource. It is not a table property or a query option. You choose it when you create or edit the compute, and every query on that compute can then use it.
| Compute type | Photon status |
|---|---|
| SQL warehouses (serverless, pro, classic) | On by default. You cannot turn it off. |
| Serverless compute for notebooks and jobs | Managed by Databricks. You do not pick an engine. |
| All-purpose clusters | Your choice. Set it when you create or edit the cluster. |
| Job clusters | Your choice, in the cluster definition of the job. |
| Lakeflow Declarative Pipelines (Delta Live Tables) | Configurable in the pipeline's compute settings. |
Defaults change between releases. Check the current Databricks documentation for your cloud and workspace before you rely on this table for a decision.
Prerequisites on the cluster
Photon needs two things from the cluster:
- A Databricks Runtime version that supports Photon. Recent runtimes do. Very old ones do not.
- A supported instance type. Photon runs on a set of node types that Databricks chooses. If a node type is not supported, it does not appear as a valid choice once you select Photon.
Because both lists change over time, the examples below use placeholders. Replace them with values that are valid in your workspace.
Enabling Photon in the UI
- Open Compute and select Create compute, or edit an existing cluster.
- Under the runtime settings, find the Use Photon Acceleration checkbox.
- Select it and choose a supported node type.
- Create the cluster, or confirm the edit. An existing cluster restarts to apply the change.
Photon-enabled clusters bill at a higher rate per hour than the same cluster without Photon. The billing unit is the Databricks Unit (DBU), a measure of processing capability per hour. Chapter on cost and sizing covers how to weigh that rate against the speedup.
Enabling Photon through the Clusters API
Automation sets Photon with the runtime_engine field. The value PHOTON selects Photon. The value STANDARD selects the standard Spark engine. If you omit the field, the workspace default applies.
{
"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"
}The placeholders for spark_version and node_type_id must be replaced before the request is valid. You can list valid values with the Clusters API calls for runtime versions and node types, or with the Databricks CLI.
The same runtime_engine field appears in the cluster definition of a job. Setting it there makes each job run start a Photon cluster.
Checking that Photon is active
Turning Photon on does not guarantee that every query uses it. You need two checks: one on the compute, and one on the query.
Check the compute
- In the cluster configuration page, the Photon checkbox is selected.
- In the cluster JSON view,
runtime_engineisPHOTON. - For a SQL warehouse, there is nothing to check, because Photon is always on.
Check the query
Run EXPLAIN FORMATTED on your query and read the physical plan. Photon operators carry a Photon prefix, such as PhotonScan, PhotonGroupingAgg and PhotonBroadcastHashJoin. The next chapters cover plan reading in detail. For now, you only need to see whether the prefix is present.
EXPLAIN FORMATTED
SELECT c.region, SUM(o.amount) AS total
FROM orders o
JOIN customers c ON o.customer_id = c.customer_id
WHERE o.order_date >= '2024-01-01'
GROUP BY c.region;Read the output from the top. A plan that starts with a Photon operator and has Photon operators for the scan, join and aggregation means most of the work runs natively. A plan where some operators have no prefix means those operators run in the standard Spark engine. The chapter on fallback explains why that happens.
The Query Profile for a finished query also marks Photon operators and shows how much task time ran in Photon. Use it to confirm the result on real runs.
A decision flow for enabling Photon
Common errors and gotchas
- The node type is missing from the list. Photon supports only some instance types. Choose another type, or turn Photon off for that cluster.
- The setting did not take effect. Edits to a running cluster apply after a restart. Confirm the restart finished before you run tests.
- Photon is on but the plan shows no Photon operators. The query uses a feature that Photon does not cover, such as a Python UDF. The cluster setting is correct. The query is the cause.
- A job is slower or costs more. Some workloads, such as very short queries or ones dominated by Python code, gain little from Photon. The higher DBU rate can then outweigh the saving. Measure before you standardize on it.
- Cluster policies block the setting. Workspace admins can fix the engine in a cluster policy. If you cannot change the checkbox, ask which policy applies to you.
- Pools and shared clusters. Cluster pools and shared compute can restrict which node types you may use. Check the pool's instance type before you assume Photon can run.
Where Photon helps most
Photon gives the largest gains on SQL and DataFrame work over Delta and Parquet data that is dominated by scans, joins, aggregations and wide tables. Typical examples are ETL transformations, large aggregations and interactive analytics. It gives little benefit to work that does not run through its engine, such as Python UDFs, RDD code, and machine learning training loops. Keep this in mind when you choose which clusters to switch.
Exercise
A teammate says they enabled Photon on a cluster, but a query still runs slowly and EXPLAIN FORMATTED shows operators with no Photon prefix. Name two checks you would make, and say why enabling Photon alone does not prove the query uses it.
Show answer
First, confirm in the cluster JSON that runtime_engine is PHOTON and that the cluster restarted after the change. Second, read the plan to find which operators lack the prefix, and look for features Photon does not cover, such as a Python UDF. Photon is a property of the compute, but each operator in a query runs in Photon only if Photon supports it. Unsupported operators fall back to the standard Spark engine, so the setting being on does not mean the whole query runs natively.
Exercise
You manage a nightly job that runs a PySpark pipeline made almost entirely of Python UDFs. Should you expect Photon to cut its cost? Explain.
Show answer
Probably not. Python UDFs run outside the Photon engine, so most of the work gets no speedup, while the Photon cluster bills at a higher DBU rate. Replace the UDFs with built-in functions first, then test Photon and compare run time and cost against the baseline.