Developing Postgres' Prefetching Algorithm - Melanie Plageman - PGCon 2022

Developing a prefetching algorithm for Postgres that balances timeliness and resource usage, adapting to various storage types, consumption rates, and system resources to maintain consistent I/O performance and minimize excess buffers and requests.

Key takeaways
  • Developing Postgres’ Prefetching Algorithm should consider time and I/O patterns to model storage systems and workloads.
  • The algorithm should balance timeliness and limited waiting for the client with keeping resource use as low as possible.
  • Prefetching should adapt to different storage types, consumption rates, and system resources.
  • The goal is to maintain a consistent number of in-flight I/Os, not exceeding the storage’s max IOPS.
  • Feedback-adjusted prefetching is important to adjust the prefetch rate based on observed demand rate and latency.
  • The simulator helps evaluate the prefetch algorithm, as real storage and workloads are challenging to model.
  • The demand rate is the minimum of the consumer’s desired consumption rate and the storage’s max IOPS.
  • The prefetch controller should have opposing forces to adjust up and down.
  • The algorithm should minimize excess buffers, waiting on the consumer, and extra I/O requests.
  • Configuring the prefetch algorithm involves setting the starting prefetch rate, headroom value, and rate limiter.
  • The algorithm should accommodate different types of storage prefetching, such as sequential and irregular access.