Sub topic 11
Reducing start time with instance pools
This chapter assumes you know how a cluster is built (a driver plus workers), the difference between all-purpose and job clusters, and how DBU and cloud charges combine. It covers what an instance pool is, how clusters use one, what it costs, and where pools fail.
Why cluster start is slow
When you start a classic cluster, Databricks asks the cloud provider for virtual machines. It waits for them to boot, installs the Databricks Runtime, and then starts Spark. This usually takes several minutes. For an all-purpose cluster you start once in the morning, that delay is minor. For a job cluster that is created and destroyed on every run, the delay is paid every time. A pipeline that runs every 10 minutes can spend a large share of its time waiting for machines.
An instance pool is a set of idle, ready-to-use virtual machines that Databricks keeps for you. A cluster attached to a pool takes its machines from the pool instead of asking the cloud provider for new ones. When the cluster ends, the machines go back to the pool for the next cluster.
Pools apply to classic compute only. Serverless compute has no node types or pools to configure, because Databricks manages the machine supply.
How a pool works
A pool has a fixed node type and a few capacity settings. Clusters that attach to it get their driver and worker nodes from it.
| Setting | API field | Meaning |
|---|---|---|
| Node type | `node_type_id` | The VM size of every instance in the pool. Fixed when the pool is created. |
| Minimum idle | `min_idle_instances` | Instances kept ready even when no cluster uses them. |
| Maximum capacity | `max_capacity` | A cap on idle plus in-use instances. |
| Idle timeout | `idle_instance_autotermination_minutes` | How long an idle instance above the minimum stays in the pool before it is released. |
| Preloaded runtimes | `preloaded_spark_versions` | Runtime versions installed on idle instances in advance. |
The pool tries to keep min_idle_instances ready. When a cluster requests nodes, the pool hands out idle instances first. If it has too few, it requests more from the cloud provider, up to max_capacity. Those extra instances start at the usual slow speed. Instances above the minimum that sit idle longer than the timeout are terminated.
Preloaded runtimes
Even with an idle VM, the runtime image must be present before Spark can start. If you list the runtime version in preloaded_spark_versions, idle instances already have it. A cluster that uses a different version still works, but it must install that version first, which costs time. Preload the versions you actually use, and keep the list short.
What a pool costs
Pools change the billing picture in one specific way.
- Databricks does not charge DBUs for instances that sit idle in a pool.
- The cloud provider does charge for those idle instances, because they are real virtual machines that you pay for.
- When a cluster uses pool instances, DBU charges apply to the cluster as usual.
So a pool trades money for speed. Every minute an idle instance waits is cloud infrastructure spend with no work attached. The minimum idle count is the main cost control. If min_idle_instances is 5 and the node type costs $0.30 per hour, you pay about $1.50 per hour for the idle floor, around the clock, whether or not anyone uses it.
With min_idle_instances set to 0, the pool keeps no standing reserve. Instances that finish a job stay in the pool until the idle timeout, so back-to-back runs reuse them. That gives most of the benefit for frequent jobs at a much lower idle cost.
Creating a pool
You can create a pool in the UI under Compute, or with the Instance Pools API. This request body creates a pool on AWS. Node type names and availability settings differ on Azure and GCP.
{
"instance_pool_name": "etl-pool",
"node_type_id": "i3.xlarge",
"min_idle_instances": 2,
"max_capacity": 20,
"idle_instance_autotermination_minutes": 30,
"preloaded_spark_versions": ["15.4.x-scala2.12"],
"aws_attributes": {
"availability": "ON_DEMAND"
}
}Send it to POST /api/2.0/instance-pools/create. The response contains an instance_pool_id, which clusters use to attach to the pool.
Attaching a cluster to a pool
In a cluster definition you replace node_type_id with instance_pool_id. The node type then comes from the pool. This is an all-purpose cluster on the pool, with autoscaling and auto termination as in the earlier chapters.
{
"cluster_name": "team-interactive-pooled",
"spark_version": "15.4.x-scala2.12",
"instance_pool_id": "<pool-id>",
"autoscale": {
"min_workers": 1,
"max_workers": 4
},
"autotermination_minutes": 60,
"data_security_mode": "USER_ISOLATION"
}A job cluster attaches the same way, inside new_cluster. Each run then takes its nodes from the pool and returns them when the run ends.
{
"name": "nightly-etl-pooled",
"job_clusters": [
{
"job_cluster_key": "etl_cluster",
"new_cluster": {
"spark_version": "15.4.x-scala2.12",
"instance_pool_id": "<pool-id>",
"num_workers": 2,
"data_security_mode": "USER_ISOLATION"
}
}
],
"tasks": [
{
"task_key": "ingest",
"job_cluster_key": "etl_cluster",
"notebook_task": {
"notebook_path": "/Workspace/Users/[email protected]/ingest"
}
}
]
}Replace <pool-id> with the real ID before you send either request.
Scripting both steps
This Python script creates a pool, then a cluster that uses it. It reads the workspace URL and a token from environment variables, so no secret appears in the code.
import os
import requests
host = os.environ["DATABRICKS_HOST"].rstrip("/")
headers = {"Authorization": f"Bearer {os.environ['DATABRICKS_TOKEN']}"}
pool_body = {
"instance_pool_name": "etl-pool",
"node_type_id": "i3.xlarge",
"min_idle_instances": 0,
"max_capacity": 10,
"idle_instance_autotermination_minutes": 20,
"preloaded_spark_versions": ["15.4.x-scala2.12"],
}
resp = requests.post(f"{host}/api/2.0/instance-pools/create",
headers=headers, json=pool_body, timeout=30)
resp.raise_for_status()
pool_id = resp.json()["instance_pool_id"]
cluster_body = {
"cluster_name": "team-interactive-pooled",
"spark_version": "15.4.x-scala2.12",
"instance_pool_id": pool_id,
"num_workers": 2,
"autotermination_minutes": 60,
"data_security_mode": "USER_ISOLATION",
}
resp = requests.post(f"{host}/api/2.1/clusters/create",
headers=headers, json=cluster_body, timeout=30)
resp.raise_for_status()
print("cluster_id:", resp.json()["cluster_id"])Driver and worker pools
By default the driver uses the same pool as the workers. The cluster API also accepts driver_instance_pool_id, which lets the driver come from a different pool. Use it when the driver needs a different node size than the workers, for example a larger driver for jobs that collect results. Each pool has only one node type, so two sizes require two pools.
Common errors and gotchas
- Pool at capacity. If idle plus in-use instances reach
max_capacity, new clusters cannot get nodes and fail to start or wait. Setmax_capacityabove the sum of what all attached clusters could request at once, and watch for several clusters sharing one pool. - Idle floor forgotten. A pool created for a test with
min_idle_instancesof 10 keeps costing money after the test. Delete pools you no longer use, or set the minimum to 0. - Runtime not preloaded. A cluster that asks for a version missing from
preloaded_spark_versionsstill starts, but you lose part of the speedup. - Node type cannot change. The node type belongs to the pool. To use a different size, create another pool.
- Mixing
node_type_idandinstance_pool_id. A pooled cluster takes its node type from the pool. Do not specify both in a cluster definition. - Pool sharing and governance. Pool permissions control who can attach clusters to a pool. Cluster policies can fix
instance_pool_idto a specific value, so users can only create clusters on approved pools. - Not for serverless. Serverless compute does not use your pools. If start time is the problem and the workload fits serverless, serverless may remove the need for a pool.
When to use a pool
| Situation | Pool a good fit? | Reason |
|---|---|---|
| Many short jobs per hour, each on a new job cluster | Yes | Start time is a large share of each run. |
| One interactive cluster started each morning | Usually no | One slow start per day is cheap to accept. |
| Bursty workloads with many clusters at once | Yes, with a sized `max_capacity` | Instances are reused between clusters. |
| Workload already runs on serverless | No | Serverless has its own managed capacity. |
| Strict budget with unpredictable use | Cautiously, with `min_idle_instances` of 0 | Avoids a standing idle charge. |
Exercise
A pool has min_idle_instances set to 3, a node type that costs $0.40 per hour in cloud charges, and no clusters attached. Roughly what do you pay per hour for the pool, and do you pay DBUs for it?
Show answer
About $1.20 per hour in cloud infrastructure charges (3 instances times $0.40). You pay no DBUs, because Databricks does not charge DBUs for idle pool instances. DBUs apply only once a cluster is running on the instances.
Exercise
A job cluster definition contains both node_type_id: "i3.xlarge" and an instance_pool_id. What should you change, and why?
Show answer
Remove node_type_id. A pooled cluster takes its node type from the pool, so the field is redundant and can conflict with the pool's node type.
Exercise
A pipeline runs every 15 minutes on a new job cluster and spends about 5 minutes of each run waiting for the cluster to start. You want to cut the wait without paying for idle machines all day. Which pool settings would you choose?
Show answer
Set min_idle_instances to 0 and idle_instance_autotermination_minutes to a value above 15, such as 20. Instances released by one run then stay in the pool and are reused by the next run, so the pool pays for idle machines only between runs. Add the runtime version to preloaded_spark_versions, and set max_capacity high enough for the cluster's size.