0
Varnish Cache
Step by step
Ins
e

rt

bu
sin
es

sl
og
ic
he
re
About Varnish Cache
● Web app accelerator	

● Fast	

● Flexible
VCL
•
•

Varnish Configuration Language	


•
•

Hook custom logic into the flow	


Applies to transactions that flow through ...
About Varnish Software
● The company behind Varnish Cache	

● Offers “Varnish Plus” - consisting of:	

○

Additional softw...
Goal
Knowing what to do to speed up your website.

Designing a web app for
Varnish
● Build apps from the ground up for Varnish	

● Intelligent cache usage	

● Proper cache i...
Incremental
implementations
● Deploy Varnish on existing apps	

● Gradually increase caching	

● “Low hanging fruits” first
Requirements
● Linux or FreeBSD	

● Virtualization is OK, not awesome	

● Tuning is only for high traffic
Step 1: Installing
Varnish
Difficulty level: Easy



Payoff: Minor
Step 1: Pass through only
● Passive Varnish	

○

return(pass) in vcl_recv	


● Powerful load balancing	

● Health checks b...
Step 2: Cache static
assets
Difficulty level: Trivial



Payoff: Minor
Step 2: Cache static
assets
● Cache images, CSS, Javascript	

● Backend concurrency decrease	

● Backend bandwidth decreas...
Step 3: Compression
Difficulty level: Trivial



Payoff: Medium
Step 3: Compression
● GZip compress CSS/Javascript	

○

JQuery standard: 263KB	


○

JQuery minified: 91KB	


○

JQuery gzi...
Step 4: Semi-static
caching
Difficulty level: Medium



Payoff: High
Step 4: Semi-static
content caching
● Dynamically rendered content	

● Expensive to render	

● Almost never changes	

● Se...
Step 4: Semi static (2/2)
● Manual cache expiry	

● Magic URLs	

● Shift-refresh from special IP-range	

● Web interface f...
Step 5: Autopurge
Difficulty level: Medium

Payoff: High
Step 5: Autopurge
● Backend generates purge requests	

● Set TTL to ~forever	

● Invalidate on change	

● Can be difficult ...
Step 6: Grace mode
Difficulty level: Easy



Payoff: High
Step 6: Grace mode
•

Originally developed to mitigate pile-ups


•

Can serve “graced” content when fresh content
is unav...
Grace mode (2)
•

Both req.grace and beresp.grace must accept
the old object	


•

Tip: Set req.grace to 10s normally and ...
Step 7: Content
composition with ESI
Difficulty level: Hard	



Payoff: High
Edge Side Includes (ESI)
Horrible Designed News Site Blah

Article	

snippet 1

Welcome, Foobar (logout)

Article	

snippe...
Edge Side Includes (ESI)
TTL: 1800minutes

TTL: 30min

TTL: 60min, user specific

TTL: 30min
TTL: 1min

TTL: 30min

TTL: 3...
Step 7: Content
composition
● Edge Side Includes (ESI)	

● Split web pages into pieces	

○

Individual caching policies	

...
<html><body>	

... <esi:include src="/frontpage/
breaking" />	

... <esi:include src="/frontpage/latest"
/>	

... <!-- Do ...
Step 8: Advanced cache
invalidation
Difficulty level: Hard

Payoff: High
Step 8: Advanced cache
invalidation
● Sometimes a page relies on multiple “objects” for
invalidation	

● Finding out what ...
Advanced cache
invalidation (2/2)
● Tag pages with custom headers	

○

X-Skus: 49834, 34321, 4343	


● Execute with bans o...
Conclusions
● High rewards with little work	

● 3 - 15 days to reach “high” payoff	

● Requires backend knowledge to do si...
Q &A
Varnish Cache - step by step
Varnish Cache - step by step
Varnish Cache - step by step
Varnish Cache - step by step
Varnish Cache - step by step
Varnish Cache - step by step
Varnish Cache - step by step
Varnish Cache - step by step
Upcoming SlideShare
Loading in...5
×

Varnish Cache - step by step

575

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
575
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Varnish Cache - step by step"

  1. 1. Varnish Cache Step by step
  2. 2. Ins e rt bu sin es sl og ic he re
  3. 3. About Varnish Cache ● Web app accelerator ● Fast ● Flexible
  4. 4. VCL • • Varnish Configuration Language • • Hook custom logic into the flow Applies to transactions that flow through the cache Main hooks used: vcl_recv and vcl_fetch
  5. 5. About Varnish Software ● The company behind Varnish Cache ● Offers “Varnish Plus” - consisting of: ○ Additional software ○ 24/7 support ○ Professional services
  6. 6. Goal Knowing what to do to speed up your website.

  7. 7. Designing a web app for Varnish ● Build apps from the ground up for Varnish ● Intelligent cache usage ● Proper cache invalidation ● Monitoring
  8. 8. Incremental implementations ● Deploy Varnish on existing apps ● Gradually increase caching ● “Low hanging fruits” first
  9. 9. Requirements ● Linux or FreeBSD ● Virtualization is OK, not awesome ● Tuning is only for high traffic
  10. 10. Step 1: Installing Varnish Difficulty level: Easy
 
 Payoff: Minor
  11. 11. Step 1: Pass through only ● Passive Varnish ○ return(pass) in vcl_recv ● Powerful load balancing ● Health checks built in ● Excellent for debugging webapps
  12. 12. Step 2: Cache static assets Difficulty level: Trivial
 
 Payoff: Minor
  13. 13. Step 2: Cache static assets ● Cache images, CSS, Javascript ● Backend concurrency decrease ● Backend bandwidth decrease ● Minor CPU usage decrease
  14. 14. Step 3: Compression Difficulty level: Trivial
 
 Payoff: Medium
  15. 15. Step 3: Compression ● GZip compress CSS/Javascript ○ JQuery standard: 263KB ○ JQuery minified: 91KB ○ JQuery gzipped: 32KB ● Compress in one place only ● Reuse compression ● Move CPU load from backend
  16. 16. Step 4: Semi-static caching Difficulty level: Medium
 
 Payoff: High
  17. 17. Step 4: Semi-static content caching ● Dynamically rendered content ● Expensive to render ● Almost never changes ● Set short TTL (10-120 seconds) ● Mitigates traffic peaks
  18. 18. Step 4: Semi static (2/2) ● Manual cache expiry ● Magic URLs ● Shift-refresh from special IP-range ● Web interface for ban or purge
  19. 19. Step 5: Autopurge Difficulty level: Medium
 Payoff: High
  20. 20. Step 5: Autopurge ● Backend generates purge requests ● Set TTL to ~forever ● Invalidate on change ● Can be difficult for composite pages ○ Map relationships between data and pages
  21. 21. Step 6: Grace mode Difficulty level: Easy
 
 Payoff: High
  22. 22. Step 6: Grace mode • Originally developed to mitigate pile-ups
 • Can serve “graced” content when fresh content is unavailable
 • Unavailable means • • backend down object busy
  23. 23. Grace mode (2) • Both req.grace and beresp.grace must accept the old object • Tip: Set req.grace to 10s normally and 1 hour when backend is down

  24. 24. Step 7: Content composition with ESI Difficulty level: Hard 
 Payoff: High
  25. 25. Edge Side Includes (ESI) Horrible Designed News Site Blah Article snippet 1 Welcome, Foobar (logout) Article snippet 2 Top 10 popular news items Article snippet 3 Article snippet 4
  26. 26. Edge Side Includes (ESI) TTL: 1800minutes TTL: 30min TTL: 60min, user specific TTL: 30min TTL: 1min TTL: 30min TTL: 30min
  27. 27. Step 7: Content composition ● Edge Side Includes (ESI) ● Split web pages into pieces ○ Individual caching policies ○ One piece = one URL ● Live stitching of content ● Works with compressed content as well
  28. 28. <html><body> ... <esi:include src="/frontpage/ breaking" /> ... <esi:include src="/frontpage/latest" /> ... <!-- Do we like the cache to meddle with content? --> </body><html>
  29. 29. Step 8: Advanced cache invalidation Difficulty level: Hard
 Payoff: High
  30. 30. Step 8: Advanced cache invalidation ● Sometimes a page relies on multiple “objects” for invalidation ● Finding out what object need to expire what pages can be hard ● Typically a problem in e-commerce and media
  31. 31. Advanced cache invalidation (2/2) ● Tag pages with custom headers ○ X-Skus: 49834, 34321, 4343 ● Execute with bans or hashninja ● Possible database driven expiry (triggers)
  32. 32. Conclusions ● High rewards with little work ● 3 - 15 days to reach “high” payoff ● Requires backend knowledge to do significant changes ● We talked about what to do - if you want to learn more about how please read the book or sign up for training.
  33. 33. Q &A
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×