Sub topic 17
Sizing compute and weighing Photon's cost
This chapter assumes you can create a cluster or SQL warehouse, read a query plan, and know that Photon is a native, vectorized engine. Here you decide whether Photon's speedup justifies its price, and how large the compute should be.
How Photon is billed
Photon runs on the same hardware as standard Spark, but Databricks charges a higher rate for it. The rate is measured in DBUs (Databricks Units), a unit of processing capability billed per hour. A Photon-enabled cluster consumes more DBUs per hour than the same cluster without Photon. Check the current multiplier for your cloud and compute type on the Databricks pricing page, because it changes.
The cost of a job is roughly:
cost = runtime_hours × (DBUs per hour × price per DBU + VM cost per hour)Photon pays off when the runtime drops by more than the rate increases. If Photon raises the hourly rate by 1.5x, the job must run in less than two thirds of the original time just to break even.
Where Photon usually pays off
- Scan-heavy queries over large Delta tables.
- Joins and aggregations over many rows.
- Wide tables where columnar processing helps.
- Queries that already read little data. These gain less, since the time goes elsewhere.
Photon helps less for queries dominated by Python UDFs, small data, or waiting on external systems. Those operators fall back to Spark, so you pay the higher rate for little gain.
Sizing compute
More workers do not always mean faster queries. Use these checks in the Query Profile or Spark UI:
- Spill to disk. If tasks spill, give each task more memory with memory-optimized nodes, or fewer tasks per node.
- Underused cores. If few tasks run at once, extra workers sit idle. Parallelism is limited by the number of files and partitions read.
- Long shuffles. Shuffle-heavy work benefits from fewer, larger nodes, because less data crosses the network.
- Idle time. Use auto-termination on clusters, and let SQL warehouses stop when idle.
A worked comparison
Suppose a nightly job takes 40 minutes without Photon at 10 DBUs per hour. With Photon it takes 20 minutes at 15 DBUs per hour.
| Setup | Runtime | DBU rate | DBUs used |
|---|---|---|---|
| Standard | 40 min | 10 per hour | 6.7 |
| Photon | 20 min | 15 per hour | 5.0 |
Photon is cheaper here, and the job finishes sooner. If the Photon run had taken 30 minutes, it would use 7.5 DBUs and cost more. Remember the VM cost: it is billed by time, so a shorter run also lowers that part.
Exercise
A job takes 60 minutes on standard compute at 8 DBUs per hour. With Photon it takes 35 minutes at 12 DBUs per hour. Which option uses fewer DBUs, and by how many?
Show answer
Standard uses 8 × 1 = 8 DBUs. Photon uses 12 × 35/60 = 7 DBUs. Photon uses 1 DBU fewer and also finishes 25 minutes sooner.
Exercise
Tasks in your Photon query spill heavily to disk. Is adding more workers the best first fix?
Show answer
Not necessarily. Spill means each task lacks memory. Use memory-optimized nodes or reduce the data per task. Adding workers only helps if it lowers the data each task handles.