Back to all reviewers

Cache performance preservation

neondatabase/neon
Based on 3 comments
Markdown

When implementing database failover or restart mechanisms, ensure performance consistency by preserving and prewarming caches. Database performance can significantly degrade after restarts due to cold caches (buffer pools, file system cache, query plan cache), especially for large workloads.

Database Markdown

Reviewer Prompt

When implementing database failover or restart mechanisms, ensure performance consistency by preserving and prewarming caches. Database performance can significantly degrade after restarts due to cold caches (buffer pools, file system cache, query plan cache), especially for large workloads.

Implement a cache prewarming strategy:

  1. Periodically persist cache state to external storage (e.g., S3)
  2. During failover, load cache state into the new instance before accepting traffic
  3. Ensure clean handover between primaries during failover with proper sequencing:
    • Avoid concurrent primaries on the same timeline
    • Complete promotion before routing traffic
    • Validate replay of all committed transactions

Example code for cache state persistence:

struct ComputeSpec {
    // ...existing fields
    
    /// Whether to do auto-prewarm at start
    pub lfc_auto_prewarm: bool,
    
    /// Interval in seconds for periodic cache dumps
    pub lfc_dump_interval_sec: Option<i32>
}

// In the cache manager
fn periodic_cache_dump() {
    if let Some(interval) = config.lfc_dump_interval_sec {
        schedule_task(Duration::from_secs(interval as u64), || {
            // Dump cache state to persistent storage
            store_cache_state_to_s3();
        });
    }
}

For read-heavy workloads, consider implementing hot secondaries that can handle read traffic while maintaining cache warmth, providing both scaling benefits and faster failover.

3
Comments Analyzed
Markdown
Primary Language
Database
Category

Source Discussions