SlideShare a Scribd company logo
getting started with varnish
Varnish Cache	

Step by Step
Federico G. Schwindt	

Technical Presales Engineer	

Varnish Software
getting started with varnish
AboutVarnish Software
● The company behindVarnish Cache	

● Offers “Varnish Plus” - consisting of:	

○ Additional software	

○ 24/7 support	

○ Professional services
Insert business logic here
AboutVarnish Cache
• Web app accelerator	

• Fast 	

• we measure TTBF in µs	

• Flexible	

• Some assembly required :-)
VCL
• Varnish Configuration Language	

• Applies to transactions that flow through the
cache	

• You can hook custom logic into the flow	

• Main hooks used: vcl_recv{} and
vcl_backend_response{}
getting started with varnish
Goal
Knowing what to do to speed up your website.

getting started with varnish
Designing a web app for
Varnish
● Build apps from the ground up forVarnish	

● Intelligent cache usage with cache headers	

● Proper cache invalidation	

● Monitoring
getting started with varnish
Incremental
implementations
● DeployVarnish on existing apps	

● Gradually increase caching	

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

● Virtualization is OK, not awesome	

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



Payoff: Minor
Step 1: Pass through only
● PassiveVarnish	

○ return(pass) in vcl_recv{}	

● Powerful load balancing	

● Health checks built in	

● Excellent for debugging webapps
getting started with varnish
Step 2: Cache static
assets
Difficulty level:Trivial



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

● Backend concurrency decrease	

● Backend bandwidth decrease	

● Minor CPU usage decrease
Step 3: Compression
Difficulty level:Trivial



Payoff: Medium
getting started with varnish
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
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	

● Set short TTL (10-120 seconds)	

● Mitigates traffic peaks
Step 4: Semi static (2/2)
● Manual cache expiry	

● Magic URLs	

● Shift-refresh from special IP-range	

● Web interface for ban or purge
Difficulty level: Medium

Payoff: High
Step 5:Autopurge
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
Difficulty level: Easy



Payoff: High
Step 6: Grace mode
getting started with varnish
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
Grace mode (2)
• Period set via beresp.grace	

• Serving actually controlled in vcl_hit{}	

• Tip: Use 10s normally and 1 hour when backend
is down

Difficulty level: Hard	



Payoff: High
Step 7: Content
composition with ESI
Article	

snippet 1
Article	

snippet 4
Article	

snippet 3
Article	

snippet 2
Welcome, Foobar (logout)
Top 10 popular news items
Horrible Designed News Site Blah
Edge Side Includes (ESI)
TTL: 30min
TTL: 30minTTL: 30min
TTL: 30min
TTL: 60min, user specific
TTL: 1min
TTL: 1800minutes
Edge Side Includes (ESI)
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
<html><body>	

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

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

... <!-- Do we like the cache to meddle
with content? -->	

</body><html>
Difficulty level: Hard

Payoff: High
Step 8:Advanced cache
invalidation
Step 8:Advanced cache
invalidation (1/2)
● 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
Advanced cache
invalidation (2/2)
● Tag pages with custom headers	

○ X-Skus: 49834, 34321, 4343	

● Execute with bans or enhanced cache invalidation 	

● Possible database driven expiry (triggers)
Step 9 TCP/IP Tuning
• The defaults in Linux are great	

• if you are Linus Torvalds and you’re browsing
with Arena	

• somaxconn, rmem, wmem, fin timeout, ...
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.
Q & A

More Related Content

KEY
Introduction to Varnish VCL
PDF
Using advanced options in MariaDB Connector/J
PDF
Building better Node.js applications on MariaDB
PDF
Memcached Code Camp 2009
PDF
EWD 3 Training Course Part 34: QEWD Resilient Mode
PDF
Next Generation DevOps in Drupal: DrupalCamp London 2014
PDF
Where is my cache architectural patterns for caching microservices by example
PPTX
ProxySQL for MySQL
Introduction to Varnish VCL
Using advanced options in MariaDB Connector/J
Building better Node.js applications on MariaDB
Memcached Code Camp 2009
EWD 3 Training Course Part 34: QEWD Resilient Mode
Next Generation DevOps in Drupal: DrupalCamp London 2014
Where is my cache architectural patterns for caching microservices by example
ProxySQL for MySQL

What's hot (20)

KEY
Nginx - Tips and Tricks.
PDF
Streaming millions of Contact Center interactions in (near) real-time with Pu...
PDF
PDF
Proxysql ha plam_2016_2_keynote
ODP
Cassandra as Memcache
PDF
Introduction to .Net Driver
PDF
Proxysql sharding
PDF
ProxySQL Tutorial - PLAM 2016
PDF
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
PDF
Parallel Replication in MySQL and MariaDB
PDF
Enterprise Drupal Application & Hosting Infrastructure Level Monitoring
KEY
Caching: A Guided Tour - 10/12/2010
PDF
Tomcatx performance-tuning
PPT
Redis vs NCache - A detailed feture level comparison
PDF
Nginx caching
PDF
Tulsa tech fest 2010 - web speed and scalability
PDF
Os Harkins
PDF
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
PDF
Where Django Caching Bust at the Seams
PDF
Caching your rails application
Nginx - Tips and Tricks.
Streaming millions of Contact Center interactions in (near) real-time with Pu...
Proxysql ha plam_2016_2_keynote
Cassandra as Memcache
Introduction to .Net Driver
Proxysql sharding
ProxySQL Tutorial - PLAM 2016
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Parallel Replication in MySQL and MariaDB
Enterprise Drupal Application & Hosting Infrastructure Level Monitoring
Caching: A Guided Tour - 10/12/2010
Tomcatx performance-tuning
Redis vs NCache - A detailed feture level comparison
Nginx caching
Tulsa tech fest 2010 - web speed and scalability
Os Harkins
Webinar slides: MySQL & MariaDB load balancing with ProxySQL & ClusterControl...
Where Django Caching Bust at the Seams
Caching your rails application
Ad

Similar to getting started with varnish (20)

PDF
Varnish Cache - step by step
PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
PDF
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
PDF
PPTX
Starting with varnish cache
ODP
PHP London Dec 2013 - Varnish - The 9 circles of hell
PDF
PDF
Tips for going fast in a slow world: Michael May at OSCON 2015
PDF
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
PPT
Varnish and Drupal- Accelerating Website Performance and Flexibility with Var...
ODP
When dynamic becomes static - the next step in web caching techniques
PPTX
Analysis of Google Page Speed Insight
KEY
Faster Frontends
PPTX
10 things you can do to speed up your web app today stir trek edition
PPTX
Building Lightning Fast Websites (for Twin Cities .NET User Group)
PDF
Web performance optimization - MercadoLibre
PDF
Performance tuning of Websites
ODP
When dynamic becomes static : the next step in web caching techniques
ODP
When dynamic becomes static : the next step in web caching techniques
PDF
Web performance mercadolibre - ECI 2013
Varnish Cache - step by step
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
Saving The World From Guaranteed APOCALYPSE* Using Varnish and Memcached
Starting with varnish cache
PHP London Dec 2013 - Varnish - The 9 circles of hell
Tips for going fast in a slow world: Michael May at OSCON 2015
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
Varnish and Drupal- Accelerating Website Performance and Flexibility with Var...
When dynamic becomes static - the next step in web caching techniques
Analysis of Google Page Speed Insight
Faster Frontends
10 things you can do to speed up your web app today stir trek edition
Building Lightning Fast Websites (for Twin Cities .NET User Group)
Web performance optimization - MercadoLibre
Performance tuning of Websites
When dynamic becomes static : the next step in web caching techniques
When dynamic becomes static : the next step in web caching techniques
Web performance mercadolibre - ECI 2013
Ad

More from Varnish Software (20)

PDF
Ask Me Anything on authentication & authorisation in Varnish
PDF
Boozt.com Use Case
PPTX
Akamai connector for varnish
PPTX
Varnish High Availability
PDF
PostNord: Copy On Write
PPTX
Varnish extend
PDF
Streaming with Varnish
PPTX
Edgestash
PPTX
What is new in varnish plus
PDF
Varnish Extend demo
PDF
Varnish extend introduction
PDF
Cedexis introduction
PDF
Secure content caching
PDF
Microservices
PDF
Varnishtest
PDF
Lightning fast with Varnish
PDF
E-commerce use case
PDF
Access control
PPTX
Varnish TLS
Ask Me Anything on authentication & authorisation in Varnish
Boozt.com Use Case
Akamai connector for varnish
Varnish High Availability
PostNord: Copy On Write
Varnish extend
Streaming with Varnish
Edgestash
What is new in varnish plus
Varnish Extend demo
Varnish extend introduction
Cedexis introduction
Secure content caching
Microservices
Varnishtest
Lightning fast with Varnish
E-commerce use case
Access control
Varnish TLS

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
KodekX | Application Modernization Development
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation_ Review paper, used for researhc scholars
Review of recent advances in non-invasive hemoglobin estimation
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Chapter 3 Spatial Domain Image Processing.pdf
KodekX | Application Modernization Development
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Network Security Unit 5.pdf for BCA BBA.
The Rise and Fall of 3GPP – Time for a Sabbatical?

getting started with varnish