Choosing a database instance size without prior knowledge of the workload can lead to inefficiencies and excessive compute usage. Lakebase Postgres addresses this with an autoscaling feature that eliminates manual sizing, utilizing in-place VM resizing and a monitoring algorithm for CPU, memory, and working set size.
Lakebase Postgres separates compute and storage layers, allowing independent resizing of compute nodes without affecting the database. The autoscaling algorithm relies on three signals: CPU load (cpuGoalCU), memory use (memGoalCU), and compute-cache working set size (lfcGoalCU). The CPU load is monitored every five seconds, aiming to maintain it at or below 90% capacity. Memory usage is tracked at two frequencies: overall memory every five seconds and Postgres-specific memory every 100 milliseconds, with a goal to keep usage below 75% of allocated RAM. The compute cache evaluates active data access efficiency, adjusting size based on workload.
The working set is estimated using a modified HyperLogLog algorithm that records timestamps for page accesses, allowing for distinct page estimates over various time frames. The algorithm projects future working-set growth to allocate sufficient cache while capping it at 75% of RAM.
Resizing the compute involves four components: the autoscaler-agent, vm-monitor, Kubernetes scheduler, and NeonVM. Scaling up occurs when any of the three goals indicate a need for more resources, while scaling down includes verification to ensure sufficient memory remains for operations. Timely adjustments in both directions are prioritized to minimize costs.