Sub topic 14
Photon and the runtime engine setting
This chapter assumes you know basic Spark concepts (jobs, stages, tasks, shuffles) and how to create a cluster in the Databricks workspace. It covers what Photon changes, how to turn it on, and how it affects sizing and cost.
What Photon is
Photon is a vectorized query engine written in C++. It replaces parts of the standard Spark JVM execution engine while keeping the same Spark APIs. You do not change your SQL or DataFrame code. Photon speeds up operators such as scans, filters, aggregations, and joins. It helps most on large Delta and Parquet reads, wide aggregations, and join-heavy SQL.
Photon does not speed up everything. Python UDFs, RDD code, and very small jobs run mostly in the normal engine. Operators that Photon does not support fall back to standard Spark inside the same query.
The runtime engine setting
In the cluster API, the runtime_engine field selects the engine. It takes one of these values:
| Value | Meaning |
|---|---|
| `STANDARD` | Standard Databricks Runtime, no Photon |
| `PHOTON` | Photon-enabled runtime |
| `NULL` or omitted | The platform chooses, based on the runtime and node type |
In the UI this appears as a "Use Photon Acceleration" checkbox. Photon needs a supported runtime version and a supported instance family. If the node type is not supported, the option is unavailable.
{
"cluster_name": "etl-photon",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"runtime_engine": "PHOTON",
"autoscale": {
"min_workers": 2,
"max_workers": 8
},
"autotermination_minutes": 30
}How Photon changes sizing and cost
Photon clusters bill at a higher DBU rate than standard clusters on the same nodes. A job that finishes in half the time can still cost less overall, but only if the speedup exceeds the rate difference. Check this with a measurement instead of assuming it.
Photon also changes how you read utilization. A faster scan can make a cluster look underused on CPU, because tasks finish sooner. Photon uses off-heap memory, so memory-heavy queries can behave differently from the same query on the standard engine. Re-measure after switching. Do not carry over the old size.
Common errors
- Enabling Photon on a Python UDF-heavy job and seeing no gain while paying the higher rate.
- Comparing runs on different data sizes or with a warm cache on one side.
- Judging only runtime. Compare cost (DBUs plus infrastructure) as well.
- Forgetting that a cluster policy can fix or restrict the engine setting.
Exercise
A nightly job uses mostly Python UDFs. It takes 60 minutes on a standard cluster. You enable Photon and it takes 55 minutes, but the DBU rate is higher. Should you keep Photon, and how would you decide?
Show answer
Probably not. A 5 minute gain is small, and the higher DBU rate likely raises the total cost. Compare total cost (DBUs plus cloud infrastructure) for both runs on the same data. Check the Spark UI to confirm that few operators ran in Photon. Keep Photon only if the cost per run drops.