Skip to content

Commit 5590c09

Browse files
committed
Added varnish hitrate docs
1 parent 9eed62c commit 5590c09

File tree

2 files changed

+207
-134
lines changed

2 files changed

+207
-134
lines changed
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
---
2+
myst:
3+
html_meta:
4+
description: Learn how to improve your Varnish cache hit rate on Hypernode by identifying automatic cache purges, analyzing hit/miss patterns, and optimizing URL normalization to boost performance and efficiency.
5+
title: Improving Varnish Cache Hit Rate on Hypernode
6+
---
7+
8+
# Improving Your Varnish Cache Hit Rate
9+
10+
A higher Varnish cache hit rate means more pages are served directly from cache.
11+
This reduces backend resource usage on your Hypernode, improves page load speed, and helps your shop handle more concurrent visitors without performance degradation.
12+
13+
A low hit rate often indicates that cache isn’t being reused effectively, typically caused by misconfiguration, frequent invalidation, or too much variation in URLs.
14+
15+
This guide takes you step-by-step from verifying that your cache is active to diagnosing and improving your hit ratio.
16+
17+
## Before You Begin
18+
19+
Typical cache hit rates:
20+
- **Below 10%** → Cache is barely reused
21+
- **30–70%** → Improvement possible (depends on shop type)
22+
- **Above 80%** → Generally healthy
23+
24+
Keep in mind:
25+
- Staging environments typically have low hit rates
26+
- B2B webshops often have lower hit rates due to personalization
27+
28+
29+
# Step 1 — Verify Varnish Is Enabled
30+
31+
Ensure Varnish is properly enabled on your Hypernode and configured in your
32+
application (e.g. Magento 2).
33+
34+
For Magento 2, verify:
35+
- Varnish is selected as the caching application
36+
- The correct VCL is generated and loaded
37+
- Full Page Cache (FPC) is enabled
38+
39+
For a complete guide on how to configure Varnish in Magento 2 see:
40+
https://docs.hypernode.com/ecommerce-applications/magento-2/how-to-configure-varnish-for-magento-2-x.html#how-to-configure-varnish-for-magento-2-x
41+
42+
```{tip}
43+
Tip: The [elgentos/magento2-varnish-extended](https://github.com/elgentos/magento2-varnish-extended) extension improves Magento’s
44+
default VCL configuration and marketing parameter handling.
45+
```
46+
47+
# Step 2 — Check if Pages Are Being Cached
48+
49+
Use `curl` to inspect response headers:
50+
51+
```console
52+
curl -I https://yourdomain.com
53+
```
54+
55+
Look for:
56+
- `X-Cache: HIT` → Served from Varnish
57+
- `X-Cache: MISS` → Served from backend
58+
- `Age` → How long the object has been cached
59+
- `X-Magento-*` headers → Useful Magento cache debug info only visible when developer mode is enabled.
60+
61+
If most responses return `MISS`, caching is not being reused effectively.
62+
63+
You can also inspect these headers in your browser via:
64+
Developer Tools → Network tab → Select request → Response Headers
65+
66+
---
67+
68+
# Step 3 — Measure Your Cache Hit Rate
69+
70+
Run:
71+
72+
```console
73+
varnishstat -1 -f MAIN.cache_hit -f MAIN.cache_miss
74+
```
75+
76+
This shows:
77+
- `MAIN.cache_hit` → Cached responses served
78+
- `MAIN.cache_miss` → Requests sent to backend
79+
80+
A high miss count relative to hits indicates room for improvement.
81+
82+
For live monitoring:
83+
84+
```console
85+
varnishstat
86+
```
87+
88+
---
89+
90+
# Step 4 — Common Causes of Low Hit Rates
91+
92+
## 1. Pages Bypassing Varnish
93+
94+
Some pages are intentionally not cached:
95+
- Checkout
96+
- Customer account pages
97+
- Requests containing `Set-Cookie` headers
98+
99+
This is expected behavior.
100+
101+
## 2. Frequent Cache Invalidations
102+
103+
If cache clears happen frequently, reuse becomes impossible.
104+
105+
Common causes:
106+
- Stock or pricing integrations
107+
- Magento cron jobs performing full cache purges
108+
- Extensions invalidating excessive cache entries
109+
110+
Best practice:
111+
Perform targeted purges (specific URLs or cache tags) instead of full cache
112+
flushes.
113+
114+
---
115+
116+
## 3. Marketing & Tracking Parameters
117+
118+
Tracking parameters create separate cache entries for identical content.
119+
120+
Examples:
121+
- `utm_source`
122+
- `utm_medium`
123+
- `gclid`
124+
- `fbclid`
125+
126+
Example problem:
127+
- /product-x
128+
- /product-x?utm_source=google
129+
130+
These generate separate cache objects unless normalized.
131+
132+
Solution:
133+
134+
Strip non-essential tracking parameters in VCL.
135+
136+
```{tip}
137+
The [elgentos/magento2-varnish-extended](https://github.com/elgentos/magento2-varnish-extended) module improves this behavior.
138+
```
139+
---
140+
141+
## 4. URL Normalization Issues
142+
143+
Different URL formats fragment your cache.
144+
145+
Examples:
146+
- `/category` vs `/category/`
147+
- `?Color=Red` vs `?color=red`
148+
- Unsorted query parameters
149+
- Session IDs in URLs
150+
151+
Normalize URLs to ensure identical content maps to a single cache object.
152+
153+
---
154+
155+
## 5. Non-Cacheable Magento Blocks
156+
157+
In Magento, a single block marked as non-cacheable can disable Full Page Cache
158+
for the entire page.
159+
160+
Search for non-cacheable blocks:
161+
162+
```console
163+
grep -R "cacheable=\"false\"" app/code vendor
164+
```
165+
If found:
166+
- Verify the block truly needs to be dynamic
167+
- Remove cacheable="false" if unnecessary
168+
- Use AJAX or Customer Data Sections for dynamic content
169+
170+
Even one unnecessary non-cacheable block can severely impact hit rate.
171+
172+
# Optional — Enable Magento Developer Mode for Debugging
173+
174+
Developer mode provides more detailed error output:
175+
```console
176+
magerun2 deploy:mode:set developer
177+
```
178+
179+
Or:
180+
```console
181+
php bin/magento deploy:mode:set developer
182+
```
183+
184+
# Debugging Tools
185+
186+
## varnishlog
187+
Inspect detailed request handling:
188+
```bash
189+
varnishlog
190+
```
191+
Look for recurring MISS patterns on pages that should be cacheable.
192+
193+
## varnishncsa
194+
Show hit/miss per URL:
195+
```bash
196+
varnishncsa -F '%U%q %{Varnish:hitmiss}x'
197+
```
198+
Filter for hits:
199+
```bash
200+
varnishncsa -F '%U%q %{Varnish:hitmiss}x' | grep hit
201+
```
202+
203+
## Hypernode Insights (If Available)
204+
Use Hypernode Insights to:
205+
- Monitor hit/miss ratios
206+
- Detect purge spikes
207+
- Correlate cache drops with deployments or cron jobs

docs/hypernode-platform/tools/improving-varnish-cache-hit.rate.md

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)