TLDR: The 2Q Algorithm - Addressing LRU's Sub-Optimality
Date: 2020-11-29 Source: https://arpitbhayani.me/blogs/2q-cache
Overview
Explore the 2Q cache eviction algorithm, an improvement over LRU, used in databases like Postgres. Learn how it optimizes performance! LRU is one of the most widely used cache eviction algorithms that span its utility across multiple database systems.
Key Points
- LRU is one of the most widely used cache eviction algorithms that span its utility across multiple database systems.
- Sub-optimality during DB scans: If the database table is bigger than the LRU cache, the DB process, upon scanning the table will wipe out the entire LRU cache and fill it with the pages from just one scanned table.
- Sub-optimality in evictions: LRU algorithm works with a single dimension - recency - as it removes the pages from the buffer on the basis of recent accesses.
- Simplified 2Q: Simplified 2Q algorithm works with two buffers: the primary LRU buffer - Am and a secondary FIFO buffer - A1.