Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 5 min read How-to mediumAdept

Autoscaling in Action: Postgres Load Testing with pgbench

A pgbench load test against Neon serverless Postgres runs a CPU-heavy query, SELECT log(factorial(32000)) / log(factorial(20000)), to trigger autoscaling. On ¼ vCPU the query spends about 1.9 s in planning, because constant folding happens there, so a modest number of concurrent clients is enough to make the compute scale within a ¼–7 CU range. The walkthrough covers the pgbench flags (-f, -c, -T, -P), reading EXPLAIN ANALYZE output and interpreting the results: roughly 6 s average latency, about 5 TPS and a high latency standard deviation.

Assumes: PostgreSQL basicscommand-line tools

Related posts

  • Dynamically estimating and scaling Postgres’ working set size

    Neon mediumAdept

    Neon autoscales Postgres compute to keep the workload's working set in memory, using a modified HyperLogLog whose register bits are replaced with timestamps so the number of distinct pages accessed can be estimated for any lookback window. A heuristic scans windows from a 5-minute offset up to one hour and treats the point where the estimate jumps sharply as the end of the current workload's plateau. Scaling then projects working set growth to avoid repeated cache evictions. In benchmarks this matched fixed-size compute performance at 30% lower cost, roughly tripled throughput on a bursty pgbench workload, and raised cache hit rate from 30-70% to 100% on a batch workload.

  • Autoscaling Lakebase Postgres

    Neon hardMaster

    Neon's Lakebase Postgres resizes compute in place about once every 81 seconds by taking the maximum of three target sizes: CPU load (one-minute average kept under 90%), memory (polled every 100 ms by an in-VM monitor and kept under 75%), and the working set of the compute cache. The working set comes from a modified HyperLogLog that stores timestamps instead of bits, so it can estimate distinct pages for any window from 1 to 60 minutes. The algorithm then looks for a jump in that curve to find where the current workload ends, and projects growth forward to the next 20-second interval. Resizes are applied to running QEMU/KVM VMs via NeonVM, with a modified Kubernetes scheduler approving upscales, live migration when a node is full, and in-VM checks before any downscale.

  • Performance tips for Neon Postgres

    Neon mediumAdept

    Neon's serverless Postgres follows mostly standard Postgres tuning, plus a few Neon-specific checks. Size compute at roughly 100 connections per GB of RAM, use pooling and autoscaling, then find slow queries with pg_stat_statements and EXPLAIN (ANALYZE, BUFFERS). Fix them with indexes, REINDEX and autovacuum tuning against bloat, and by keeping the local file cache hit ratio (shown in neon_stat_file_cache) above 99%. For faster ingests, batch inserts, drop unused indexes, offload reads to ephemeral read replicas, and test changes safely on a database branch.

  • PostgresBench: A Reproducible Benchmark for Postgres Services

    ClickHouse mediumAdept

    PostgresBench is an open, reproducible benchmark for managed Postgres services built on pgbench's TPC-B-like workload (256 clients, 16 threads, 10-minute runs, three runs each) at ~100 GB and ~500 GB scale factors, with default configs, HA disabled and all services in us-east-2. In the first cohort, ClickHouse's NVMe-backed managed Postgres reached about 28.7K TPS on 16 vCPU/64 GB at 100 GB, versus 14.8K for Crunchy Bridge, 12.6K for Aurora, 8.6K for Neon and 8.1K for RDS, and held about 26K TPS at 500 GB. ClickHouse attributes the lead to co-located local NVMe storage, which avoids network round trips on every fsync and WAL commit in write-heavy workloads. Scripts and raw JSON results are on GitHub for verification and community submissions, though the vendor-run setup and absence of pricing comparisons are worth weighing.

  • Scaling serverless Postgres: How we implement autoscaling

    Neon mediumAdept

    Neon autoscales serverless Postgres by running each compute endpoint in a QEMU/KVM VM on Kubernetes (via its NeonVM controller) and hot-adding or removing CPU and memory based on load average. A per-node autoscaler-agent makes scaling decisions but must get every upscale approved by a modified Kubernetes scheduler plugin, which acts as the single source of truth to prevent memory overcommit. Post-copy live migration (~100ms pauses) moves VMs off full nodes, kept cheap by separated storage. Inside each VM, a vm-informant uses cgroup memory.high notifications to freeze Postgres briefly (up to 20ms) while requesting more memory, and resizes a tmpfs-backed local file cache with 1MB LRU chunks that gave one user a 4x speedup.

The quest for software engineering knowledge.

Look:
Layout: