Sub topic 4
Autoscaling clusters and auto stop
This chapter assumes you know what a SQL warehouse is, the difference between serverless, pro, and classic types, and how warehouse size works. It covers two settings that control how many clusters run and how long an idle warehouse stays on.
Clusters inside a warehouse
A SQL warehouse is made of one or more clusters. The warehouse size sets how big each cluster is. Autoscaling sets how many clusters run at once. A query runs on a single cluster, so adding clusters does not make one query faster. It lets more queries run at the same time.
Choose the size for the heaviest single query. Choose the cluster range for the number of users or dashboards that hit the warehouse together.
Autoscaling
You set a minimum and a maximum number of clusters. The warehouse starts with the minimum. When queries begin to queue because the running clusters are busy, the warehouse adds clusters, up to the maximum. When the load drops, it removes clusters again.
Some practical points:
- With min and max both set to 1, the warehouse never scales out. Queries queue when it is busy.
- A higher maximum protects response times during peaks, but it also raises the most you can spend.
- Scaling out takes time on pro and classic warehouses. Serverless warehouses start and scale much faster, so they handle bursts better.
Auto stop
Auto stop shuts the warehouse down after it has been idle for a set number of minutes. A stopped warehouse costs nothing for compute. The next query starts it again, and that query waits for the start.
The trade-off is cost against first-query delay:
| Setting | Benefit | Cost |
|---|---|---|
| Short idle time | Less money spent while idle | More cold starts for users |
| Long idle time | Fewer cold starts | You pay for idle compute |
Typical starting points are a few minutes for serverless, where restarts are fast, and 10 to 45 minutes for pro and classic, where restarts are slower. The right value depends on how bursty your traffic is. The defaults and allowed ranges differ by warehouse type, so check the options in the UI.
Configuring both settings
You set these on the warehouse's configuration page, or through the SQL Warehouses API. This request body creates a warehouse that scales between 1 and 3 clusters and stops after 10 idle minutes.
curl -X POST "$DATABRICKS_HOST/api/2.0/sql/warehouses" \
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "reporting-wh",
"cluster_size": "Small",
"min_num_clusters": 1,
"max_num_clusters": 3,
"auto_stop_mins": 10
}'Common mistakes
- Raising the size to fix queueing. Queueing comes from too many concurrent queries, so raise the maximum cluster count instead.
- Raising the maximum cluster count to fix one slow query. A single query uses one cluster, so use a larger size.
- Setting auto stop to never stop. A forgotten warehouse then runs, and bills, around the clock.
Exercise
A dashboard refreshes 20 queries at once every hour. Each query finishes in a few seconds when run alone, but during refresh many of them queue. Which setting do you change, and why?
Show answer
Raise the maximum number of clusters. Each query is fast alone, so the size is fine. The queueing comes from concurrency, and extra clusters let more queries run in parallel. A short auto stop also suits this hourly pattern, especially on serverless.
Exercise
Why does a very long auto stop time raise cost without improving query speed once the warehouse is running?
Show answer
Auto stop only controls when an idle warehouse shuts down. It does not change how fast queries run. A long value just means you pay for compute during idle periods, in return for avoiding a cold start on the next query.