VarnishApache Airflow

Memory Exhaustion from Prefork MPM Behind Varnish

critical
Resource ContentionUpdated Jan 1, 2025

Apache prefork MPM's process-per-connection model becomes memory-inefficient when fronted by Varnish, as cache misses can trigger sudden process spawn bursts that exhaust available RAM and force swapping.

How to detect:

Monitor system memory usage and swap activity alongside varnish_cache_hitpass rate. When cache hit ratio drops suddenly and Apache memory consumption spikes with corresponding swap increase, prefork MPM is spawning too many processes to handle cache miss traffic.

Recommended action:

Migrate from prefork MPM to event MPM (or worker MPM if event is not compatible) to reduce per-connection memory overhead. If using mod_php, switch to PHP-FPM to enable threaded MPMs. Carefully tune MaxRequestWorkers based on available memory: calculate (Total RAM - other services) / (average Apache process memory) and set with 20% safety margin. Configure Varnish grace mode to serve stale content during traffic spikes.