Skip to content

Commit db1b4d7

Browse files
committed
Moved varnish-hit-rate docs to tools/varnish + improvements based on internal Feedback
1 parent 8682f6a commit db1b4d7

File tree

1 file changed

+61
-32
lines changed

1 file changed

+61
-32
lines changed

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

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,46 @@ myst:
77

88
# Improving Your Varnish Cache Hit Rate
99

10-
A higher Varnish cache hit rate means more requests are served directly from cache.
10+
A higher Varnish cache hit rate means more requests are served directly from the cache.
1111
This reduces resource usage on your Hypernode, improves page load speed, and helps your shop handle more concurrent visitors without performance degradation.
1212

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.
13+
A low hit rate often indicates that cache is not being reused effectively, typically caused by misconfiguration, frequent invalidation, or too much variation in URLs.
1414

1515
This guide takes you step-by-step from verifying that your cache is active to diagnosing and improving your hit ratio.
1616

1717
## Before You Begin
1818

1919
Typical cache hit rates:
2020
- **Below 10%** → Cache is barely reused
21-
- **30–70%** → Improvement possible (depends on shop type)
22-
- **Above 80%** → Generally healthy
21+
- **30–70%** → Improvement possible (depends on shop type and traffic patterns)
22+
- **Above 80%** → Generally healthy for most shops
2323

2424
Keep in mind:
2525
- Staging environments typically have low hit rates
2626
- B2B webshops often have lower hit rates due to personalization
27+
- Recently flushed caches temporarily reduce hit rates until the cache warms up
2728

29+
Cache hit rate should always be evaluated in context. Traffic volume, personalization, and recent deployments directly affect cache reuse.
2830

29-
# Step 1 — Verify Varnish Is Enabled
31+
## When a Low Hit Rate Is Expected
32+
33+
A low hit rate does not always indicate a problem. It is normal when:
34+
35+
- Traffic volume is low
36+
- The cache was recently flushed
37+
- Most visitors are logged in
38+
- The shop uses heavy personalization
39+
- You are working in a staging environment
40+
41+
Investigate further only if traffic is stable, the cache is warmed up, and the hit rate remains consistently low.
42+
43+
## Step 1 — Verify Varnish Is Enabled
3044

3145
Ensure Varnish is properly enabled on your vhost and configured in your
3246
application (e.g. Magento 2).
3347

3448
For Magento 2, verify:
35-
- That varnish is enabled on the vhost
49+
- That Varnish is enabled on the vhost
3650
- Varnish is selected as the caching application
3751
- The correct VCL is generated and loaded
3852
- Full Page Cache (FPC) is enabled
@@ -43,9 +57,17 @@ For a step-by-step guide on activating and configuring Varnish in Magento 2, ple
4357
Tip: The [elgentos/magento2-varnish-extended](https://github.com/elgentos/magento2-varnish-extended) extension improves Magento’s default VCL configuration and marketing parameter handling.
4458
```
4559

46-
# Step 2 — Check if Pages Are Being Cached
60+
## Step 2 — Check if Pages Are Being Cached
61+
62+
Using `varnishncsa` from the CLI to see in real time which pages are cached and which are not:
63+
```console
64+
varnishncsa -F '%U%q %{Varnish:hitmiss}x'
65+
```
66+
Look for:
67+
- `hit` → Served from Varnish
68+
- `miss` → Served from backend
4769

48-
Use `curl` to inspect response headers:
70+
Alternatively, you can use `curl` to inspect response headers:
4971

5072
```console
5173
curl -I https://yourdomain.com
@@ -54,7 +76,7 @@ curl -I https://yourdomain.com
5476
Review the following headers:
5577

5678
- **`Set-Cookie`**
57-
If `PHPSESSID` is present, Varnish will not cache the response.
79+
If a Set-Cookie header (such as PHPSESSID) is present, Varnish will typically not cache the response.
5880

5981
- **`Cache-Control`**
6082
Should **not** contain `private`, `no-store`, or `no-cache`.
@@ -70,7 +92,7 @@ If most responses return `MISS` (for example in `X-Magento-Cache-Debug` or simil
7092
You can also inspect these headers in your browser via:
7193
Developer Tools → Network tab → Select request → Response Headers
7294

73-
# Step 3 — Measure Your Cache Hit Rate
95+
## Step 3 — Measure Your Cache Hit Rate
7496

7597
Run:
7698

@@ -84,10 +106,10 @@ This shows:
84106

85107
A high miss count relative to hits indicates room for improvement.
86108

87-
For live monitoring:
109+
For live monitoring of which requests are hitting Varnish, use:
88110

89111
```console
90-
varnishstat
112+
varnishlog
91113
```
92114

93115
Look for:
@@ -96,9 +118,11 @@ Look for:
96118
- `Age` → Indicates how long (in seconds) the object has been cached.
97119
- `X-Magento-*` headers → Provides Magento cache/debug information (visible in developer mode).
98120

99-
# Step 4 — Common Causes of Low Hit Rates
121+
Alternatively, reuse the varnishncsa command from Step 2 for live hit/miss monitoring.
122+
123+
## Step 4 — Common Causes of Low Hit Rates
100124

101-
## 1. Pages Bypassing Varnish
125+
### 1. Pages Bypassing Varnish
102126

103127
Some pages are intentionally not cached:
104128
- Checkout
@@ -107,9 +131,9 @@ Some pages are intentionally not cached:
107131

108132
This is expected behavior.
109133

110-
## 2. Frequent Cache Invalidations
134+
### 2. Frequent Cache Invalidations
111135

112-
If cache clears happen frequently, reuse becomes impossible.
136+
If cache clears happen frequently, cache reuse becomes nearly impossible.
113137

114138
Common causes:
115139
- Stock or pricing integrations
@@ -120,7 +144,7 @@ Best practice:
120144
Perform targeted purges (specific URLs or cache tags) instead of full cache
121145
flushes.
122146

123-
## 3. Marketing & Tracking Parameters
147+
### 3. Marketing & Tracking Parameters
124148

125149
Tracking parameters create separate cache entries for identical content.
126150

@@ -134,7 +158,7 @@ Example problem:
134158
- /product-x
135159
- /product-x?utm_source=google
136160

137-
These generate separate cache objects unless normalized.
161+
These generate separate cache objects unless the URLs are normalized.
138162

139163
Solution:
140164
Strip non-essential tracking parameters in VCL.
@@ -143,7 +167,7 @@ Strip non-essential tracking parameters in VCL.
143167
The [elgentos/magento2-varnish-extended](https://github.com/elgentos/magento2-varnish-extended) module improves this behavior.
144168
```
145169

146-
## 4. URL Normalization Issues
170+
### 4. URL Normalization Issues
147171

148172
Different URL formats fragment your cache.
149173

@@ -153,57 +177,62 @@ Examples:
153177
- Unsorted query parameters
154178
- Session IDs in URLs
155179

156-
Normalize URLs to ensure identical content maps to a single cache object.
180+
Normalize URLs to ensure identical content maps to a single cache object in Varnish.
157181

158-
## 5. Non-Cacheable Magento Blocks
182+
### 5. Non-Cacheable Magento Blocks
159183

160-
In Magento, a single block marked as non-cacheable can disable Full Page Cache
161-
for the entire page.
184+
In Magento, a single block marked as non-cacheable can disable Full Page Cache (FPC) for the entire page.
162185

163186
Search for non-cacheable blocks:
164187

165188
```console
166189
grep -R "cacheable=\"false\"" app/code vendor
167190
```
191+
168192
If found:
169193
- Verify the block truly needs to be dynamic
170194
- Remove cacheable="false" if unnecessary
171195
- Use AJAX or Customer Data Sections for dynamic content
172196

173197
Even one unnecessary non-cacheable block can severely impact hit rate.
174198

175-
# Optional — Enable Magento Developer Mode for Debugging
199+
## Optional — Enable Magento Developer Mode for Debugging
200+
201+
Enable developer mode temporarily for debugging purposes:
176202

177-
Developer mode provides more detailed error output:
178203
```console
179204
magerun2 deploy:mode:set developer
180205
```
181206

182207
Or:
208+
183209
```console
184210
php bin/magento deploy:mode:set developer
185211
```
186212

187-
# Debugging Tools
213+
## Debugging Tools
214+
215+
### varnishlog
188216

189-
## varnishlog
190217
Inspect detailed request handling:
191-
```bash
218+
```console
192219
varnishlog
193220
```
194221
Look for recurring MISS patterns on pages that should be cacheable.
195222

196-
## varnishncsa
223+
### varnishncsa
224+
197225
Show hit/miss per URL:
198-
```bash
226+
```console
199227
varnishncsa -F '%U%q %{Varnish:hitmiss}x'
200228
```
201229
Filter for hits:
202-
```bash
230+
```console
203231
varnishncsa -F '%U%q %{Varnish:hitmiss}x' | grep hit
204232
```
205233

206-
## Hypernode Insights (If Available)
234+
### Hypernode Insights (If Available)
235+
207236
Use Hypernode Insights to:
208237
- Monitor hit/miss ratios
209238
- Detect purge spikes

0 commit comments

Comments
 (0)