Magento Performance: Debugging Varnish Cache Fragmentation
Problem
A common production issue in Magento stores is higher server load and increased TTFB, even though Magento Varnish Cache is enabled.
In many cases, the root cause is low magento Varnish cache hit ratio, which means more requests are reaching Magento instead of being served from cache.
Cache inefficiencies can come from:
- Cache misses
- Aggressive pass rules
- Cookie behaviour
- Cache fragmentation
Diagnostics
Start by collecting Varnish runtime statistics.
varnishstat
Example snapshot:
MAIN.client_req 1200000
MAIN.cache_hit 900000
MAIN.cache_miss 120000
MAIN.cache_hitpass 80000
MAIN.backend_req 200000
MAIN.s_pass 75000
MAIN.n_lru_nuked 45000
Cache Effectiveness
Cache Hit
MAIN.cache_hit 900000
Requests served directly from magento Varnish cache.
Cache Miss
MAIN.cache_miss 120000
Requests that were not present in cache and fetched from backend.
Cache Hit Ratio
cache_hit / (cache_hit + cache_miss)
Indicates how efficiently Varnish serves cacheable traffic.
Cache Hitpass
MAIN.cache_hitpass 80000
Requests intentionally bypassing cache due to pass rules or uncacheable responses.
If this number is high, review:
- Pass rules
- Cookies
- Headers
Backend Load Indicators
Backend Requests
MAIN.backend_req 200000
Total number of requests reaching Magento.
Higher backend requests usually correlate with higher TTFB.
Cache Memory Pressure
LRU Nuked Objects
MAIN.n_lru_nuked 45000
Objects evicted early due to memory pressure, often caused by multiple cache variants of the same page.
Total Client Requests
MAIN.client_req 1200000
Total requests received by Varnish.
Used as the base metric when evaluating cache efficiency.
Requests Passed to Backend
MAIN.s_pass 75000
Requests forced to bypass cache due to VCL pass rules.
Large values may indicate overly aggressive pass conditions.
Takeaway
When tuning Magento Varnish Cache, avoid large configuration changes at once.
Instead:
- Make incremental tweaks
- Monitor Varnish metrics after each change
- Observe impact on hit ratio and backend requests
Also remember:
When a Magento Varnish Cache is first warmed or after configuration changes, hit ratio will initially be low. It gradually improves as cache objects populate.
The goal is not a perfect hit ratio, but a stable system where most cacheable traffic is served from Varnish and backend load remains controlled.
