Loading…
Smarter Auto-Scaling for ClickHouse: The Two-Window Approach
Ashwath Singh, Manas Alekar
- Source
- Clickhouse
- Published
- Added to Yomu
Summary
ClickHouse Cloud required a vertical auto-scaling mechanism that preserves rapid scale-ups while avoiding prolonged over-provisioning after traffic drops. Operating on a single 30-hour lookback window forced scale-downs to take up to 30 hours, whereas an earlier fixed-factor CPU algorithm caused severe oscillations. The engineering team deployed a dual-window recommender pairing a 3-hour window for responsive scale-downs with a 30-hour window for single-step scale-ups. Alongside a trend-based hunting check to resolve conflicting window recommendations, the team introduced target-tracking CPU scaling using geometric mean watermarks and 10-minute median smoothing. This dual-window architecture reduced scale-down latency to 3 hours, prevented scaling oscillations, and significantly reduced infrastructure costs for variable database workloads.
Context
A single 30-hour lookback window in ClickHouse Cloud caused clusters to remain over-provisioned for up to 30 hours after traffic dropped. In addition, the existing CPU recommendation algorithm used fixed doubling or halving factors that triggered severe scaling oscillations with shorter lookback windows.
Approach / What changed
ClickHouse implemented a dual-window recommender combining a 3-hour window and a 30-hour window, using a hunting check on the previous small window trend to resolve disagreements. They also introduced target-tracking CPU scaling with 10-minute median smoothing, selecting the higher recommendation between CPU and memory analyses.
Takeaways
- Setting the target utilization to the geometric mean of the high and low watermarks guarantees reversible scaling and prevents allocation drift.
- A 3-hour lookback window enables faster scale-downs while the 30-hour window ensures single-step scale-ups to longer-term peak usage.
- Comparing the current small window against the previous small window recommendation prevents scaling oscillations when the two lookback windows disagree.