Sub topic 5
What a Cluster Costs: DBUs and Infrastructure
This chapter assumes you know what a Databricks cluster is, how a driver and workers map to Spark executors, and the difference between on-demand and spot instances. It builds the cost model that the later chapters on autoscaling, spot instances, auto-termination, and policies depend on.
Two bills for one cluster
A Databricks cluster produces two separate charges.
- Databricks charges are measured in Databricks Units (DBUs). A DBU is a unit of processing capability per hour. Databricks bills you for the DBUs your cluster consumes, at a rate in dollars per DBU.
- Cloud infrastructure charges are what your cloud provider bills you for the virtual machines, attached storage, and networking that the cluster uses. On AWS, these appear on your AWS bill as EC2 and EBS charges.
The two bills come from different vendors, show up in different places, and respond differently to your tuning choices. A cluster that looks cheap in the Databricks usage report can still be expensive on the cloud bill, and the reverse is also true.
Some details depend on the plan and cloud you use. This chapter describes the general model. Check current pricing for exact rates.
How DBUs are counted
Each node type has a DBU rate, which is the number of DBUs one instance of that type consumes per hour. Larger and more specialized instances have higher rates. A GPU instance consumes more DBUs per hour than a general-purpose instance with similar memory.
The DBU charge for a cluster is:
DBU cost per hour = (DBUs per node per hour) x (number of nodes) x (price per DBU)The number of nodes includes the driver. A cluster with 1 driver and 4 workers has 5 nodes for billing purposes, though the driver and workers can be different instance types and so can have different DBU rates.
The price per DBU depends on the compute type and your plan. Jobs compute, which runs automated workloads, is priced lower per DBU than all-purpose compute, which is used for interactive work in notebooks. SQL and serverless products have their own rates. The same Spark code can therefore cost noticeably less per hour when it runs as a scheduled job on a job cluster than when it runs on a shared interactive cluster.
The infrastructure charge
The infrastructure charge is the cloud provider's price for the instances, and it is separate from the DBU charge:
Infrastructure cost per hour = sum of instance prices + storage + networkThe instance price depends on the instance type and on the purchase option. On-demand instances cost the full list price. Spot instances cost less, often by a large margin, but the provider can reclaim them. The spot chapter covers the risks. Here, the point is that spot pricing reduces only the infrastructure part of the bill. A DBU is billed at the same rate whether the instance underneath it is on-demand or spot.
That has a practical consequence. If DBUs make up most of your cost, spot instances help less than the headline discount suggests.
Putting the two together
Suppose a cluster has one driver and four workers, all of one type. The numbers below are made up to show the arithmetic.
| Item | Value |
|---|---|
| Nodes (1 driver + 4 workers) | 5 |
| DBUs per node per hour | 1.0 |
| Price per DBU | $0.15 |
| Instance price per hour (on-demand) | $0.31 |
The hourly cost works out as follows.
- DBU charge: 5 nodes x 1.0 DBU x $0.15 = $0.75
- Infrastructure charge: 5 nodes x $0.31 = $1.55
- Total: $2.30 per hour
If the four workers move to spot instances at, say, a 60 percent discount, the infrastructure charge drops by 4 x $0.31 x 0.60 = $0.74. The new total is $1.56 per hour. The DBU charge stays at $0.75.
What the charges depend on
Both charges accumulate for as long as the cluster is running, whether or not any Spark task is executing. This single fact drives most cost control:
- The cost scales with node count, so over-provisioning workers wastes money in both bills.
- The cost scales with running time, so an idle cluster still costs money until it terminates.
- The cost scales with instance size, through both the DBU rate and the instance price.
- The cost depends on compute type, through the price per DBU.
Things that change the cost per job
Hourly cost is not the same as cost per job. A larger cluster costs more per hour but can finish sooner. If a job scales well, doubling the workers might halve the runtime, so the job costs about the same while finishing in half the time. If the job does not scale well, because of skew, a small number of partitions, or a long serial stage, doubling the workers raises the cost with little speedup.
This is why the sizing chapters measure runtime and utilization, and do not judge a cluster by its hourly price alone.
Other factors that affect the total bill:
- Startup time. Nodes are billed on the infrastructure side once the provider starts them, and the cluster is not useful until it is ready. Frequent restarts of large clusters add up. Instance pools, covered later, reduce this wait.
- Idle time. A cluster left running overnight accrues both charges. Auto-termination is the main protection.
- Photon. Photon can raise the DBU rate for a cluster. It pays off when the faster execution shortens the runtime by more than the rate increase. The decision is covered in the Photon chapter.
- Driver size. The driver is billed like any other node. Oversizing it is a common and easy-to-miss waste on clusters with many small tasks.
- Storage and data transfer. Attached volumes and cross-region transfers appear on the cloud bill and are unaffected by DBU settings.
Seeing the cost
You can find where the money goes in two places.
- Databricks usage data. The account console and the billing system tables report DBU consumption by cluster, job, user, and tags.
- Your cloud provider's billing tools. These report instance, storage, and network charges. Use cluster tags to connect the two views.
Custom tags set on a cluster are applied to the cloud resources it creates. They let you group both bills by team, project, or environment. Tags are also a natural thing to require through a cluster policy.
A cluster specification with tags looks like this:
{
"cluster_name": "etl-autoscale",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"autoscale": {
"min_workers": 2,
"max_workers": 8
},
"autotermination_minutes": 30,
"custom_tags": {
"team": "data-eng",
"cost_center": "1042"
}
}Common mistakes
- Estimating cost from the Databricks bill alone and forgetting the cloud bill, or the reverse.
- Expecting spot instances to cut the whole bill. They reduce only the infrastructure charge.
- Running scheduled production work on all-purpose clusters, which carry a higher DBU price than jobs compute.
- Comparing clusters by hourly price without comparing runtime.
- Leaving auto-termination off, or setting it very high, on interactive clusters.
Exercise
Exercise
A cluster has 1 driver and 9 workers, all of one instance type that uses 2 DBUs per node per hour. The price is $0.20 per DBU, and each instance costs $0.50 per hour on demand. (a) What is the hourly cost on demand? (b) The 9 workers move to spot instances at a 70 percent discount, and the driver stays on demand. What is the new hourly cost?
Show answer
There are 10 nodes. (a) The DBU charge is 10 x 2 x $0.20 = $4.00. The infrastructure charge is 10 x $0.50 = $5.00. The total is $9.00 per hour. (b) The DBU charge does not change, so it stays at $4.00. The infrastructure charge is the driver at $0.50 plus 9 workers at $0.50 x 0.30 = $0.15 each, which is $1.35. That gives $0.50 + $1.35 = $1.85. The new total is $5.85 per hour.
Exercise
Job A runs on a 4-worker cluster costing $3 per hour and takes 2 hours. Job B is the same job on an 8-worker cluster costing $5.50 per hour and takes 1.1 hours. Which run is cheaper, and what does this say about judging clusters by hourly price?
Show answer
Job A costs 3 x 2 = $6.00. Job B costs 5.50 x 1.1 = $6.05. They cost almost the same, though B finishes in about half the time. The larger cluster has the higher hourly price, but hourly price alone does not predict the cost of a job. Runtime must be included.