Sub topic 14
Understanding cost and monitoring a warehouse
This chapter assumes you can create a warehouse, know the size and auto stop settings, and can run queries in the SQL editor. It shows where warehouse cost comes from and how to see what a warehouse is doing.
Where the cost comes from
A SQL warehouse is billed in Databricks Units (DBUs) for as long as it is running. The meter runs whether or not queries are executing. Three settings drive the total:
| Setting | Effect on cost |
|---|---|
| Warehouse size | Each step up roughly doubles the DBUs per hour. |
| Maximum clusters | Each extra cluster that autoscaling starts is billed at the full size rate. |
| Auto stop | Sets how long an idle warehouse keeps billing before it shuts down. |
The warehouse type also changes what you pay for. Serverless warehouses include the underlying compute in the DBU rate. Pro and classic warehouses run in your cloud account, so your cloud provider bills you for the virtual machines separately.
Watching a warehouse live
Open the warehouse in SQL Warehouses and select the Monitoring tab. It shows:
- The number of running and queued queries over time.
- The number of clusters currently running.
- Query counts for a time range you choose.
Use these charts to answer two questions:
- Are queries waiting? A queue that grows while all clusters are busy means you need a higher maximum cluster count. If a single query is slow with no queue, a larger size is the better fix.
- Is capacity sitting unused? If the cluster count stays at its maximum while few queries run, the maximum is too high.
Measuring spend with system tables
The Monitoring tab shows activity, not money. For cost, query the billing system table. This query sums DBUs per day for one warehouse. It uses a named parameter, so the editor shows an input field for the warehouse ID.
SELECT
usage_date,
SUM(usage_quantity) AS dbus
FROM system.billing.usage
WHERE usage_metadata.warehouse_id = :warehouse_id
AND usage_unit = 'DBU'
AND usage_date >= current_date() - INTERVAL 30 DAYS
GROUP BY usage_date
ORDER BY usage_date;You can find the warehouse ID on the warehouse's Overview tab. Reading system.billing.usage requires access to the system catalog, which an account admin must grant. Billing rows can arrive some hours after the usage happens, so today's number is usually incomplete.
Common errors
- Tuning size when the problem is queuing. A larger size does not help if many users run small queries at once. Add clusters instead.
- Leaving long auto stop times on. Short auto stop times save money, but a stopped warehouse must start again, which delays the next query. Serverless warehouses start quickly, so they suit short auto stop times best.
- Treating the Monitoring tab as a bill. It shows load, not DBUs.
- Sharing one warehouse across unrelated teams. You cannot tell who caused the spend. Separate warehouses, or tags on them, make cost attributable.
Exercise
Users report that dashboards are slow at 9 a.m. The Monitoring tab shows one cluster running and a long queue of waiting queries. Individual queries finish quickly once they start. Which setting should you change first, and why?
Show answer
Raise the maximum cluster count. The queue shows that concurrency is the bottleneck, not the speed of any single query. A larger size would make each query faster, but it would not let more queries run at once.