libs/vm_monitor/README.md
vm-monitorThe vm-monitor (or just monitor) is a core component of the autoscaling system,
along with the autoscale-scheduler and the autoscaler-agents. The monitor has
two primary roles: 1) notifying agents when immediate upscaling is necessary due
to memory conditions and 2) managing Postgres' file cache and a cgroup to carry
out upscaling and downscaling decisions.
We scale CPU and memory using NeonVM, our in-house QEMU tool for use with Kubernetes.
To control thresholds for receiving memory usage notifications, we start Postgres
in the neon-postgres cgroup and set its memory.{max,high}.
neondatabase/autoscalingneondatabase/vm-monitor,
where initial development of the monitor happened. The repository is no longer
maintained but the commit history may be useful for debugging.The vm-monitor is loosely comprised of a few systems. These are:
axum server that accepts requests and
upgrades them to websocket connections. The server only allows one connection at
a time. This means that upon receiving a new connection, the server will terminate
and old one if it exists.CgroupWatcher polls the neon-postgres cgroup's memory
usage and sends rolling aggregates to the runner.Dispatcher, and then calling filecache
and cgroup watcher functions as needed to upscale and downscale