Sub topic 11
Reducing start time with instance pools
This chapter assumes you know how a cluster is built from a driver and workers, and that you have read the chapters on all-purpose clusters, job clusters, and the cost model. You should also be comfortable reading JSON.
Why clusters start slowly
A classic cluster takes several minutes to start. Most of that time goes to asking the cloud provider for virtual machines, waiting for them to boot, and then installing the Databricks Runtime on each one. For an interactive cluster, you pay for that wait once and then keep the cluster running. A job cluster is created for every run, so the wait is added to every run. A pipeline with many short tasks can spend more time starting than computing.
An instance pool is a set of idle, ready-to-use virtual machines that Databricks keeps for you. When a cluster attaches to a pool, it takes machines from the pool instead of requesting new ones from the cloud provider. When the cluster ends, the machines go back to the pool for the next cluster.
How a pool works
Three pool settings control the behavior:
min_idle_instancesis the number of instances the pool keeps ready even when no cluster uses them.max_capacityis the most instances the pool will hold, idle and in use together. Clusters that need more than that fail to start or scale up.idle_instance_autotermination_minutesis how long an instance above the minimum can sit idle before the pool releases it to the cloud provider.
A pool can also preload one or more Databricks Runtime versions on its idle instances. A cluster that uses a preloaded version skips the installation step, which gives the fastest start.
Creating a pool
Pools are created in the workspace UI or with the Instance Pools API (POST /api/2.0/instance-pools/create). This request body keeps two instances warm. The node type is an AWS example and differs on Azure and GCP.
{
"instance_pool_name": "etl-pool",
"node_type_id": "i3.xlarge",
"min_idle_instances": 2,
"max_capacity": 10,
"idle_instance_autotermination_minutes": 15,
"preloaded_spark_versions": ["15.4.x-scala2.12"]
}The response contains an instance_pool_id. Use it in a cluster definition.
Attaching a cluster to a pool
In the cluster definition, replace node_type_id with instance_pool_id. The pool decides the node type. The pool ID below is a placeholder, so substitute your own.
{
"cluster_name": "pooled-interactive",
"spark_version": "15.4.x-scala2.12",
"instance_pool_id": "0101-120000-pool1234",
"autoscale": {
"min_workers": 1,
"max_workers": 4
},
"autotermination_minutes": 60,
"data_security_mode": "USER_ISOLATION"
}If you want the driver on a different pool, set driver_instance_pool_id. Otherwise it uses the same pool as the workers. The same instance_pool_id field works inside a job's new_cluster block, which is where pools help most.
Cost trade-offs
Idle instances in a pool are not free. Databricks does not charge DBUs for idle pool instances, but the cloud provider charges for the virtual machines. Databricks DBU charges start only when a cluster is using an instance. So the cost of a pool is the cloud bill for min_idle_instances running around the clock, plus any idle time before instances are released.
Keep min_idle_instances at zero if you can accept a slower first start. In that case, instances stay warm for a while after a cluster releases them, which still speeds up back-to-back runs. Use a nonzero minimum only when start latency is worth the standing cost.
Common errors
- Setting
node_type_idandinstance_pool_idtogether. The pool defines the node type, so set only the pool ID. - Setting
max_capacitytoo low. Concurrent clusters compete for the same instances, and some fail to start. - Expecting pools to help serverless compute. Serverless compute is managed by Databricks and does not use pools.
- Forgetting the runtime. If a cluster asks for a runtime version that is not preloaded, it still starts faster than without a pool, but it installs the runtime on the instances first.
Exercise
A nightly job runs ten short tasks, each on its own job cluster, and most of the run time goes to cluster start. You want faster starts but the lowest standing cost. Which pool settings would you choose, and why?
Show answer
Attach the job clusters to a pool using instance_pool_id, preload the runtime version the job uses, and set min_idle_instances to 0. After the first cluster finishes, its instances stay in the pool until idle_instance_autotermination_minutes expires, so the later tasks reuse warm instances. Set max_capacity high enough for the clusters that run at the same time. A nonzero minimum would add a standing cloud charge all day for a job that runs only at night.