SlideShare a Scribd company logo
1 of 63
Download to read offline
Varnish Cache Plus 
Random notes for wise web developers 
Carlos Abalde, Roberto Moreda 
{cabalde, moreda}@allenta.com 
October 2014
Agenda 
1. Introduction 
2. Varnish 101 
3. Invalidations 
4. HTTP headers 
5. Content composition 
6. VAC 
7. VCS 
8. Device detection 
9. Varnish Plus 4.x 
10. Q&A
1. Introduction
Disclaimer 
๏ General understanding of ‘The Varnish Book’ is assumed 
‣ This is not the official Varnish Cache training 
‣ This is not a Varnish Cache internals course 
‣ This is not a Varnish module development course 
‣ This is a collection of random notes for web developers 
willing to make the most of Varnish Cache Plus 
๏ OSS Varnish Cache vs. Varnish Cache Plus 
‣ 3.x vs. 4.x
Varnish Cache 3.x 
What everybody should know 
๏ The Varnish Book 
‣ https://www.varnish-software.com/static/book/ 
๏ The Varnish Reference Manual 
‣ https://www.varnish-cache.org/docs/.../index.html 
๏ Default VCL 
‣ https://www.varnish-cache.org/trac/.../default.vcl
Varnish Cache Plus 3.x 
Components I 
๏ Support, advise & training 
๏ Varnish Enhanced Cache Invalidation 
‣ Hash Two, Hash Ninja… 
๏ Varnish Administration Console (VAC) 
๏ Varnish Custom Statistics (VCS) 
๏ Device detection
Varnish Cache Plus 3.x 
Components II 
๏ Varnish Tuner 
๏ Enhanced HTTP streaming 
๏ Packaged binary VMODs 
๏ Varnish Paywall 
๏ … and more to come shortly!
Varnish Cache Plus 3.x 
Supported platforms 
๏ 64 bits 
๏ Distributions 
‣ RedHat Enterprise Linux 5 & 6 
‣ Ubuntu Linux 12.04 LTS (precise) 
‣ Ubuntu Linux 14.04 LTS (trusty) 
‣ Debian Linux 7 (wheezy)
2. Varnish 101
Caching policy 
๏ Varnish Cache Plus would require zero configuration 
in a perfect world with perfect HTTP citizens 
‣ Correct HTTP caching headers 
‣ Vary HTTP header used wisely 
‣ HTTP cookies used conservatively 
๏ By default Varnish Cache Plus will not cache 
anything marked as private, carrying a cookie or 
including a '*' 
Vary HTTP header
VCL 
Overview 
๏ Varnish Configuration Language 
‣ Domain specific state engine 
‣ No loops, variables, functions… 
‣ Command line configuration & Tunable parameters 
๏ Translated to C code 
๏ Loaded as a dynamically generated shared library 
‣ Zero downtime & Blazingly fast
VCL 
vcl_recv I 
๏ Normalize client-input 
๏ Pick a backend / director 
๏ Re-write / extend client-input 
๏ Decide caching policy based on client-input 
๏ Access control 
๏ Security barriers
VCL 
vcl_recv II 
sub 
vcl_recv 
{ 
# 
Backend 
selection 
& 
URL 
normalization. 
if 
(req.http.host 
~ 
"^blogs.") 
{ 
set 
req.backend 
= 
blogs; 
set 
req.http.host 
= 
regsub(req.http.host,"^blogs.", 
""); 
set 
req.url 
= 
regsub(req.url, 
"^", 
"/blogs"); 
} 
else 
{ 
set 
req.backend 
= 
default; 
} 
# 
Poor 
man's 
device 
detection. 
if 
(req.http.User-­‐Agent 
~ 
"(iPad|iPhone|Android)") 
{ 
set 
req.http.X-­‐Device 
= 
"mobile"; 
} 
else 
{ 
set 
req.http.X-­‐Device 
= 
"desktop"; 
} 
}
VCL 
vcl_fetch I 
๏ Sanitize / extend backend response 
๏ Override cache duration 
‣ beresp.ttl 
- s-­‐maxage & maxage in Cache-­‐Control HTTP header 
- Expires HTTP header 
- Default TTL 
‣ Beware with TTL of hitpass objects
VCL 
vcl_fetch II 
sub 
vcl_fetch 
{ 
# 
Override 
caching 
TTL. 
if 
(beresp.http.Cache-­‐Control 
!~ 
"s-­‐maxage") 
{ 
set 
beresp.ttl 
= 
0; 
if 
(bereq.url 
~ 
".jpg(?|$)") 
{ 
set 
beresp.ttl 
= 
30s; 
} 
} 
# 
Never 
cache 
a 
Set-­‐Cookie 
header. 
if 
(beresp.ttl 
> 
0s) 
{ 
unset 
beresp.http.Set-­‐Cookie; 
} 
# 
Create 
ban-­‐lurker 
friendly 
objects. 
set 
beresp.http.X-­‐Url 
= 
bereq.url; 
}
VCL 
Request flow I
VCL 
Request flow II
Process architecture
VMODs 
๏ Shared libraries extending the VCL core 
‣ std VMOD 
- std.toupper(), std.log(), std.fileread()… 
‣ ABI (Application Binary Interface) mismatches 
๏ cookie, header, var, curl, digest, geoip, boltsort, 
memcached, redis, dns… 
๏ https://www.varnish-cache.org/vmods
Backends 
๏ Multiple backends 
‣ Selected at request time based on any request property 
๏ Probes 
‣ Per-backend periodic health checks 
- Interval, timeout, expected response… 
๏ Directors 
‣ Load balanced backend groups
Error handling 
Saint mode 
๏ Some backend may be sick for a particular object 
‣ Other objects from the same backend can still be accessed 
- Unless more than a set amount of objects are added to 
the saint mode blacklist for a specific backend 
๏ Do not request again the object to that backend for a 
period of time 
‣ Grace mode is used when all possible backends for the 
requested object have been blacklisted 
๏ Complement backend probes
Error handling 
Grace mode 
๏ A graced object is an object that has expired, but is still 
kept in cache 
‣ beresp.ttl vs. beresp.grace 
๏ Graced objects are used to 
‣ Serve outdated content if the backend is down 
- Probes or saint mode is required for this 
‣ Serve sightly staled content while fresh versions are 
fetched
Beyond caching policy 
๏ Why restricting VCL / VMODs to implement the 
caching policy? 
๏ Any logic modeled in VCL / VMODs is compiled, 
embedded & executed in the caching edger layer 
‣ 1000x times faster than typical Java / PHP apps 
- Strong restrictions 
‣ Accounting, paywalling, A/B testing…
varnishtest 
๏ Powerful Varnish-specific testing tool 
‣ Mocked clients & backends executing / 
processing HTTP requests against real Varnish 
Cache Plus instances 
‣ http://www.clock.co.uk/...varnishtest 
๏ Essential when implementing complex VCL logic 
๏ Easily integrable in any CI infrastructure
FAQ 
๏ When SSL support will be implemented? 
‣ "[...] huge waste of time and effort to even think about it." 
๏ When SPDY support will be implemented? 
‣ "[...] Varnish is not speedy, Varnish is fast! [...]" 
๏ What is the recommended value for this bizarre kernel / 
varnishd parameter I found in some random blog? 
‣ Use Varnish Tuner + Fine tune based on necessity 
‣ Pay attention to workspaces & syslog messages
3. Invalidations
Overview 
๏ Updated objects may be available before TTL 
expiration 
‣ Purges 
‣ Forced misses 
‣ Bans 
‣ Hash Two / Hash Ninja / …
Purges 
Overview 
๏ VCL 
๏ Eagerly discards an object along with all its variants 
acl 
internal 
{ 
"localhost"; 
"192.168.55.0"/24; 
} 
sub 
vcl_recv 
{ 
if 
(req.request 
== 
"PURGE") 
{ 
if 
(client.ip 
!~ 
internal) 
{ 
error 
405 
"Not 
allowed."; 
} 
return 
(lookup); 
} 
} 
sub 
vcl_hit 
{ 
if 
(req.request 
== 
"PURGE") 
{ 
purge; 
error 
200 
"Purged."; 
} 
} 
sub 
vcl_miss 
{ 
if 
(req.request 
== 
"PURGE") 
{ 
purge; 
error 
200 
"Purged."; 
} 
}
Purges 
Downsides I 
๏ What if the new object cannot be fetched after the 
invalidation? 
‣ Soft-purges VMOD 
‣ Forces misses 
๏ What if multiple objects need to be invalidated? What 
if objects need to be invalidated too frequently? 
‣ Bans 
‣ Hash Two
Purges 
Downsides II 
๏ How to invalidate hitpass objects? 
‣ Not possible in Varnish Cache Plus 3.x 
- Redesigned in Varnish Cache Plus 4.x 
- https://www.varnish-cache.org/trac/.../1033 
‣ return(pass); during vcl_recv is preferred 
when possible
Forced misses 
Overview 
๏ VCL 
๏ Forces a cache miss for the request 
‣ Useful for cache priming scripts 
sub 
vcl_recv 
{ 
if 
(req.http.X-­‐Priming-­‐Script) 
{ 
... 
set 
req.hash_always_miss 
= 
true; 
} 
... 
}
Forced misses 
Behavior 
๏ Object will always be (re)fetched from the backend 
๏ New object is put into cache and used from that point 
onward 
‣ Old object is not evicted until it’s safe to do so 
‣ Controls who takes the penalty of waiting for an 
updated object 
๏ Old objects are not freed up until expiration 
‣ This is considered a flaw and a fix is expected
Bans 
Overview 
๏ VCL or CLI 
๏ Lazily discards multiple objects matching an expression 
‣ Logical operators + Object attributes + Regular expressions 
‣ Only works on objects already in the cache 
๏ Ban lurker 
‣ Frees up memory + Keeps the ban list at a manageable size 
‣ obj.* based expressions
Bans 
Example 
sub 
vcl_recv 
{ 
if 
(req.request 
== 
"BAN") 
{ 
... 
if 
(!req.http.X-­‐Ban-­‐Url-­‐Regexp) 
{ 
error 
400 
"Empty 
URL 
regexp."; 
} 
ban("obj.http.X-­‐Url 
~ 
" 
+ 
req.http.X-­‐Ban-­‐Url-­‐Regexp); 
} 
} 
sub 
vcl_fetch 
{ 
set 
beresp.http.X-­‐Url 
= 
req.url; 
} 
sub 
vcl_deliver 
{ 
unset 
resp.http.X-­‐Url; 
}
Hash Two 
Overview 
๏ VCL + VMOD 
๏ Workarounds bans scalability 
HTTP/1.x 
200 
OK 
Transfer-­‐Encoding: 
chunked 
... 
X-­‐Tags: 
C10 
P42 
P236 
P857 
... 
ban 
obj.http.X-­‐Tags 
~ 
"(s|^)P42(s|$)"
Hash Two 
Example 
import 
hashtwo; 
sub 
vcl_recv 
{ 
if 
(req.request 
== 
"PURGE") 
{ 
... 
if 
(hashtwo.purge(req.http.X-­‐Tag) 
!= 
0) 
{ 
error 
200 
"Purged."; 
} 
else 
{ 
error 
404 
"Not 
found."; 
} 
} 
} 
sub 
vcl_fetch 
{ 
set 
beresp.http.X-­‐HashTwo 
= 
beresp.http.X-­‐Tags; 
}
4. HTTP headers
Cache related headers 
๏ Expires 
๏ Cache-Control 
๏ Last-Modified 
๏ If-Modified-Since 
๏ If-None-Match 
๏ Etag 
๏ Pragma 
๏ Vary 
๏ Age
Cache-Control 
Overview 
๏ Specifies directives that must be applied by all 
caching mechanisms (from Varnish Cache Plus to 
browser cache) 
‣ public 
| 
private 
‣ no-­‐store 
‣ no-­‐cache 
‣ max-­‐age 
‣ s-­‐maxage 
‣ must-­‐revalidate 
‣ no-­‐transform 
‣ …
Cache-Control 
beresp.ttl 
๏ Ignored in incoming client HTTP requests 
๏ Only s-­‐maxage & max-­‐age used in backend HTTP 
responses to calculate default TTL 
‣ Always overrides Expires header 
‣ Beware of Age header in client responses 
- Objects not cached client side 
- https://www.varnish-cache.org/...Caching
Vary 
๏ Indicates the response returned by the backend 
server may vary depending on headers received in 
the request 
๏ Object variants & Hit ratio 
‣ Vary: 
Accept-­‐Encoding 
- Normalization of Accept-­‐Encoding header is 
not required 
‣ Vary: 
User-­‐Agent
5. Content 
composition
Overview 
๏ Break objects into smaller fragments 
‣ Separate cache policy for each fragment 
‣ Increase hit ratio 
๏ Tools 
‣ Edge Side Includes (ESI) 
‣ AJAX 
- Beware of RTT & Cross domain policy
Edge Side Includes 
๏ Subset of ESI Language Specification 1.0 
‣ <esi:include 
src="<URL> 
" 
/> 
‣ <esi:remove>...</esi:remove> 
‣ <!-­‐-­‐esi 
...—> 
๏ set 
beresp.do_esi 
= 
true; 
‣ Separate Varnish requests 
๏ Testing ESI in dev environment
6. VAC
Overview 
๏ Central control of Varnish Cache Plus servers 
‣ Web UI + RESTful API 
- Super Fast Purger 
๏ Cache group management 
‣ Real time statistics, VCL editor, ban submission… 
๏ Varnish Agent 2
Super Fast Purger 
๏ High performance intermediary distributing 
invalidation requests to groups of Varnish 
Cache Plus servers 
‣ Leverages speed & flexibility of VCL 
‣ Keep-alive workaround 
๏ Part of the VAC RESTful API 
‣ Trivially integrable in existing applications
Change management 
๏ Easily integrable using the VAC RESTful API 
‣ git, Mercurial… hooks 
‣ Jenkins, Travis, GitLab… CI scripts 
๏ Manual VCL bundle generation 
๏ Orchestrated / programmed deployments, 
rollbacks, etc.
7. VCS
Overview 
๏ Real-time aggregated statistics 
‣ Multiple vstatdprobe daemons 
‣ One vstatd daemon 
‣ JSON + Time series API 
๏ VSM log based 
‣ Efficient circular in-memory data structure 
‣ std.log("vcs-­‐key:" 
+ 
<key 
suffix>);
Some ideas 
๏ Trending articles or sale products 
๏ Cache hits and cache misses 
๏ URLs with long load times 
๏ URLs with the most 5xx response codes 
๏ Where traffic is coming from 
๏ …
Example 
sub 
vcl_deliver 
{ 
std.log("vcs-­‐key:" 
+ 
req.http.host); 
std.log("vcs-­‐key:" 
+ 
req.http.host 
+ 
req.url); 
std.log("vcs-­‐key:TOTAL"); 
if 
(obj.hits 
== 
0) 
{ 
std.log("vcs-­‐key:MISS"); 
} 
}
API I 
๏ Stats (#requests, #misses, avg ttfb, acc body bytes, #2xx, 
#3xx…) for key named “example.com" during the last 
time windows 
‣ GET 
/key/example.com 
๏ Keys that produced the most 5xx responses during the 
last time window 
‣ GET 
/all/top_5xx 
๏ Top 5 requested keys during the last time window 
‣ GET 
/all/top/5?verbose=1
API II 
๏ Top 10 most requested keys ending with ‘.gif' 
during the last time window 
‣ GET 
/match/(.*)%5C.gif$/top 
๏ Top 50 slowest backend requests aggregating 
the last 20 time windows 
‣ GET 
/all/top_ttfb/50?b=20
8. Device detection
Overview 
๏ VMOD 
๏ DeviceAtlas 
‣ https://deviceatlas.com 
‣ Database locally deployed & Daily updated 
๏ OSS alternatives 
‣ https://github.com/serbanghita/Mobile-Detect 
‣ …
Example 
import 
deviceatlas; 
sub 
vcl_recv 
{ 
if 
(deviceatlas.lookup(req.http.User-­‐Agent, 
"isMobilePhone") 
== 
"1") 
{ 
set 
req.http.X-­‐Device 
= 
"mobile"; 
} 
elsif 
(deviceatlas.lookup(req.http.User-­‐Agent, 
"isTablet") 
== 
"1") 
{ 
set 
req.http.X-­‐Device 
= 
"tablet"; 
} 
else 
{ 
set 
req.http.X-­‐Device 
= 
"desktop"; 
} 
}
Some ideas 
๏ Redirections based on device properties 
๏ Backend selection based on device properties 
๏ Normalization of the UA header 
‣ Caching different versions (i.e. Vary header) of 
the same object based on normalized UAs 
๏ …
9. Varnish Plus 4.x
Highlights 
๏ Client / backend thread split 
‣ Background content refreshing 
๏ Redesigned purges 
‣ return(purge); during vcl_recv 
๏ Directors implemented as VMODs 
‣ Consistent hashing director 
๏ Distinction between error & synthetic responses
10. Q&A

More Related Content

What's hot

Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...Fastly
 
Altitude SF 2017: Logging at the edge
Altitude SF 2017: Logging at the edgeAltitude SF 2017: Logging at the edge
Altitude SF 2017: Logging at the edgeFastly
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cacheMarc Cortinas Val
 
Fastly CEO Artur Bergman at Altitude NYC
Fastly CEO Artur Bergman at Altitude NYCFastly CEO Artur Bergman at Altitude NYC
Fastly CEO Artur Bergman at Altitude NYCFastly
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyLeif Hedstrom
 
Reverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and VarnishReverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and VarnishEl Mahdi Benzekri
 
Altitude SF 2017: The power of the network
Altitude SF 2017: The power of the networkAltitude SF 2017: The power of the network
Altitude SF 2017: The power of the networkFastly
 
Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015Fastly
 
Rails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeRails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeMichael May
 
Herding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandboxHerding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandboxColdFusionConference
 
Advanced cache invalidation
Advanced cache invalidationAdvanced cache invalidation
Advanced cache invalidationPer Buer
 
Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2SergeyChernyshev
 
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINXDockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINXKevin Jones
 
Build your own CDN with Varnish - Confoo 2022
Build your own CDN with Varnish - Confoo 2022Build your own CDN with Varnish - Confoo 2022
Build your own CDN with Varnish - Confoo 2022Thijs Feryn
 
Load Balancing with Nginx
Load Balancing with NginxLoad Balancing with Nginx
Load Balancing with NginxMarian Marinov
 
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)Ontico
 
NGINX High-performance Caching
NGINX High-performance CachingNGINX High-performance Caching
NGINX High-performance CachingNGINX, Inc.
 
Altitude San Francisco 2018: HTTP Invalidation Workshop
Altitude San Francisco 2018: HTTP Invalidation WorkshopAltitude San Francisco 2018: HTTP Invalidation Workshop
Altitude San Francisco 2018: HTTP Invalidation WorkshopFastly
 
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Gavin Pickin
 

What's hot (20)

Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
Altitude SF 2017: Fastly GSLB: Scaling your microservice and multi-cloud envi...
 
Altitude SF 2017: Logging at the edge
Altitude SF 2017: Logging at the edgeAltitude SF 2017: Logging at the edge
Altitude SF 2017: Logging at the edge
 
cache concepts and varnish-cache
cache concepts and varnish-cachecache concepts and varnish-cache
cache concepts and varnish-cache
 
Varnish SSL / TLS
Varnish SSL / TLSVarnish SSL / TLS
Varnish SSL / TLS
 
Fastly CEO Artur Bergman at Altitude NYC
Fastly CEO Artur Bergman at Altitude NYCFastly CEO Artur Bergman at Altitude NYC
Fastly CEO Artur Bergman at Altitude NYC
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
 
Reverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and VarnishReverse proxy & web cache with NGINX, HAProxy and Varnish
Reverse proxy & web cache with NGINX, HAProxy and Varnish
 
Altitude SF 2017: The power of the network
Altitude SF 2017: The power of the networkAltitude SF 2017: The power of the network
Altitude SF 2017: The power of the network
 
Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015Tips for going fast in a slow world: Michael May at OSCON 2015
Tips for going fast in a slow world: Michael May at OSCON 2015
 
Rails Caching Secrets from the Edge
Rails Caching Secrets from the EdgeRails Caching Secrets from the Edge
Rails Caching Secrets from the Edge
 
Herding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandboxHerding cats managing ColdFusion servers with commandbox
Herding cats managing ColdFusion servers with commandbox
 
Advanced cache invalidation
Advanced cache invalidationAdvanced cache invalidation
Advanced cache invalidation
 
Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2Building your own CDN using Amazon EC2
Building your own CDN using Amazon EC2
 
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINXDockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
 
Build your own CDN with Varnish - Confoo 2022
Build your own CDN with Varnish - Confoo 2022Build your own CDN with Varnish - Confoo 2022
Build your own CDN with Varnish - Confoo 2022
 
Load Balancing with Nginx
Load Balancing with NginxLoad Balancing with Nginx
Load Balancing with Nginx
 
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
 
NGINX High-performance Caching
NGINX High-performance CachingNGINX High-performance Caching
NGINX High-performance Caching
 
Altitude San Francisco 2018: HTTP Invalidation Workshop
Altitude San Francisco 2018: HTTP Invalidation WorkshopAltitude San Francisco 2018: HTTP Invalidation Workshop
Altitude San Francisco 2018: HTTP Invalidation Workshop
 
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
Take home your very own free Vagrant CFML Dev Environment - Presented at dev....
 

Viewers also liked

できる!Varnish ~もう一歩踏み出すためのTips~
できる!Varnish ~もう一歩踏み出すためのTips~できる!Varnish ~もう一歩踏み出すためのTips~
できる!Varnish ~もう一歩踏み出すためのTips~Iwana Chan
 
Varnishのログの眺め方
Varnishのログの眺め方Varnishのログの眺め方
Varnishのログの眺め方Iwana Chan
 
Varnishの使い方~All Aboutでの使い方を例に~
Varnishの使い方~All Aboutでの使い方を例に~Varnishの使い方~All Aboutでの使い方を例に~
Varnishの使い方~All Aboutでの使い方を例に~Kazuto Ohara
 
Varnish 4.0 Release Party in Tokyo発表資料
Varnish 4.0 Release Party in Tokyo発表資料Varnish 4.0 Release Party in Tokyo発表資料
Varnish 4.0 Release Party in Tokyo発表資料Iwana Chan
 
VarnishではじめるESI
VarnishではじめるESIVarnishではじめるESI
VarnishではじめるESIIwana Chan
 
Redisととあるシステム
RedisととあるシステムRedisととあるシステム
RedisととあるシステムTakehiro Torigaki
 
料理を楽しくする画像配信システム
料理を楽しくする画像配信システム料理を楽しくする画像配信システム
料理を楽しくする画像配信システムIssei Naruta
 
EC2とVarnishで画像配信
EC2とVarnishで画像配信EC2とVarnishで画像配信
EC2とVarnishで画像配信Issei Naruta
 
大規模Redisサーバ縮小化の戦い
大規模Redisサーバ縮小化の戦い大規模Redisサーバ縮小化の戦い
大規模Redisサーバ縮小化の戦いYuto Komai
 

Viewers also liked (10)

できる!Varnish ~もう一歩踏み出すためのTips~
できる!Varnish ~もう一歩踏み出すためのTips~できる!Varnish ~もう一歩踏み出すためのTips~
できる!Varnish ~もう一歩踏み出すためのTips~
 
Varnishのログの眺め方
Varnishのログの眺め方Varnishのログの眺め方
Varnishのログの眺め方
 
Varnish
VarnishVarnish
Varnish
 
Varnishの使い方~All Aboutでの使い方を例に~
Varnishの使い方~All Aboutでの使い方を例に~Varnishの使い方~All Aboutでの使い方を例に~
Varnishの使い方~All Aboutでの使い方を例に~
 
Varnish 4.0 Release Party in Tokyo発表資料
Varnish 4.0 Release Party in Tokyo発表資料Varnish 4.0 Release Party in Tokyo発表資料
Varnish 4.0 Release Party in Tokyo発表資料
 
VarnishではじめるESI
VarnishではじめるESIVarnishではじめるESI
VarnishではじめるESI
 
Redisととあるシステム
RedisととあるシステムRedisととあるシステム
Redisととあるシステム
 
料理を楽しくする画像配信システム
料理を楽しくする画像配信システム料理を楽しくする画像配信システム
料理を楽しくする画像配信システム
 
EC2とVarnishで画像配信
EC2とVarnishで画像配信EC2とVarnishで画像配信
EC2とVarnishで画像配信
 
大規模Redisサーバ縮小化の戦い
大規模Redisサーバ縮小化の戦い大規模Redisサーバ縮小化の戦い
大規模Redisサーバ縮小化の戦い
 

Similar to Varnish Cache Plus. Random notes for wise web developers

Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSamantha Quiñones
 
Accelerate your web app with a layer of Varnish
Accelerate your web app with a layer of VarnishAccelerate your web app with a layer of Varnish
Accelerate your web app with a layer of VarnishJeremy Cook
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnishschoefmax
 
June8 presentation
June8 presentationJune8 presentation
June8 presentationnicobn
 
Rails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeRails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeFastly
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersSeravo
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with VarnishAOE
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with VarnishAOE
 
VCLをTDDで書いてデプロイする
VCLをTDDで書いてデプロイするVCLをTDDで書いてデプロイする
VCLをTDDで書いてデプロイするKengo HAMASAKI
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCLFastly
 
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...Ovadiah Myrgorod
 
Containers explained as for cook and a mecanics
 Containers explained as for cook and a mecanics  Containers explained as for cook and a mecanics
Containers explained as for cook and a mecanics Rachid Zarouali
 
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context ConstraintsAlessandro Arrichiello
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Wim Godden
 

Similar to Varnish Cache Plus. Random notes for wise web developers (20)

Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with Varnish
 
Accelerate your web app with a layer of Varnish
Accelerate your web app with a layer of VarnishAccelerate your web app with a layer of Varnish
Accelerate your web app with a layer of Varnish
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
 
June8 presentation
June8 presentationJune8 presentation
June8 presentation
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Varnish –Http Accelerator
Varnish –Http AcceleratorVarnish –Http Accelerator
Varnish –Http Accelerator
 
Varnish qconsp 2011
Varnish qconsp 2011Varnish qconsp 2011
Varnish qconsp 2011
 
Rails Caching: Secrets From the Edge
Rails Caching: Secrets From the EdgeRails Caching: Secrets From the Edge
Rails Caching: Secrets From the Edge
 
Less and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developersLess and faster – Cache tips for WordPress developers
Less and faster – Cache tips for WordPress developers
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with Varnish
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with Varnish
 
Varnish
VarnishVarnish
Varnish
 
VCLをTDDで書いてデプロイする
VCLをTDDで書いてデプロイするVCLをTDDで書いてデプロイする
VCLをTDDで書いてデプロイする
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
 
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
Create a Varnish cluster in Kubernetes for Drupal caching - DrupalCon North A...
 
Performance
PerformancePerformance
Performance
 
Containers explained as for cook and a mecanics
 Containers explained as for cook and a mecanics  Containers explained as for cook and a mecanics
Containers explained as for cook and a mecanics
 
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
[Devconf.cz][2017] Understanding OpenShift Security Context Constraints
 
Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012Caching and tuning fun for high scalability @ FOSDEM 2012
Caching and tuning fun for high scalability @ FOSDEM 2012
 
Varnish
VarnishVarnish
Varnish
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 

Varnish Cache Plus. Random notes for wise web developers

  • 1. Varnish Cache Plus Random notes for wise web developers Carlos Abalde, Roberto Moreda {cabalde, moreda}@allenta.com October 2014
  • 2. Agenda 1. Introduction 2. Varnish 101 3. Invalidations 4. HTTP headers 5. Content composition 6. VAC 7. VCS 8. Device detection 9. Varnish Plus 4.x 10. Q&A
  • 4. Disclaimer ๏ General understanding of ‘The Varnish Book’ is assumed ‣ This is not the official Varnish Cache training ‣ This is not a Varnish Cache internals course ‣ This is not a Varnish module development course ‣ This is a collection of random notes for web developers willing to make the most of Varnish Cache Plus ๏ OSS Varnish Cache vs. Varnish Cache Plus ‣ 3.x vs. 4.x
  • 5. Varnish Cache 3.x What everybody should know ๏ The Varnish Book ‣ https://www.varnish-software.com/static/book/ ๏ The Varnish Reference Manual ‣ https://www.varnish-cache.org/docs/.../index.html ๏ Default VCL ‣ https://www.varnish-cache.org/trac/.../default.vcl
  • 6. Varnish Cache Plus 3.x Components I ๏ Support, advise & training ๏ Varnish Enhanced Cache Invalidation ‣ Hash Two, Hash Ninja… ๏ Varnish Administration Console (VAC) ๏ Varnish Custom Statistics (VCS) ๏ Device detection
  • 7. Varnish Cache Plus 3.x Components II ๏ Varnish Tuner ๏ Enhanced HTTP streaming ๏ Packaged binary VMODs ๏ Varnish Paywall ๏ … and more to come shortly!
  • 8. Varnish Cache Plus 3.x Supported platforms ๏ 64 bits ๏ Distributions ‣ RedHat Enterprise Linux 5 & 6 ‣ Ubuntu Linux 12.04 LTS (precise) ‣ Ubuntu Linux 14.04 LTS (trusty) ‣ Debian Linux 7 (wheezy)
  • 10. Caching policy ๏ Varnish Cache Plus would require zero configuration in a perfect world with perfect HTTP citizens ‣ Correct HTTP caching headers ‣ Vary HTTP header used wisely ‣ HTTP cookies used conservatively ๏ By default Varnish Cache Plus will not cache anything marked as private, carrying a cookie or including a '*' Vary HTTP header
  • 11. VCL Overview ๏ Varnish Configuration Language ‣ Domain specific state engine ‣ No loops, variables, functions… ‣ Command line configuration & Tunable parameters ๏ Translated to C code ๏ Loaded as a dynamically generated shared library ‣ Zero downtime & Blazingly fast
  • 12. VCL vcl_recv I ๏ Normalize client-input ๏ Pick a backend / director ๏ Re-write / extend client-input ๏ Decide caching policy based on client-input ๏ Access control ๏ Security barriers
  • 13. VCL vcl_recv II sub vcl_recv { # Backend selection & URL normalization. if (req.http.host ~ "^blogs.") { set req.backend = blogs; set req.http.host = regsub(req.http.host,"^blogs.", ""); set req.url = regsub(req.url, "^", "/blogs"); } else { set req.backend = default; } # Poor man's device detection. if (req.http.User-­‐Agent ~ "(iPad|iPhone|Android)") { set req.http.X-­‐Device = "mobile"; } else { set req.http.X-­‐Device = "desktop"; } }
  • 14. VCL vcl_fetch I ๏ Sanitize / extend backend response ๏ Override cache duration ‣ beresp.ttl - s-­‐maxage & maxage in Cache-­‐Control HTTP header - Expires HTTP header - Default TTL ‣ Beware with TTL of hitpass objects
  • 15. VCL vcl_fetch II sub vcl_fetch { # Override caching TTL. if (beresp.http.Cache-­‐Control !~ "s-­‐maxage") { set beresp.ttl = 0; if (bereq.url ~ ".jpg(?|$)") { set beresp.ttl = 30s; } } # Never cache a Set-­‐Cookie header. if (beresp.ttl > 0s) { unset beresp.http.Set-­‐Cookie; } # Create ban-­‐lurker friendly objects. set beresp.http.X-­‐Url = bereq.url; }
  • 19. VMODs ๏ Shared libraries extending the VCL core ‣ std VMOD - std.toupper(), std.log(), std.fileread()… ‣ ABI (Application Binary Interface) mismatches ๏ cookie, header, var, curl, digest, geoip, boltsort, memcached, redis, dns… ๏ https://www.varnish-cache.org/vmods
  • 20. Backends ๏ Multiple backends ‣ Selected at request time based on any request property ๏ Probes ‣ Per-backend periodic health checks - Interval, timeout, expected response… ๏ Directors ‣ Load balanced backend groups
  • 21. Error handling Saint mode ๏ Some backend may be sick for a particular object ‣ Other objects from the same backend can still be accessed - Unless more than a set amount of objects are added to the saint mode blacklist for a specific backend ๏ Do not request again the object to that backend for a period of time ‣ Grace mode is used when all possible backends for the requested object have been blacklisted ๏ Complement backend probes
  • 22. Error handling Grace mode ๏ A graced object is an object that has expired, but is still kept in cache ‣ beresp.ttl vs. beresp.grace ๏ Graced objects are used to ‣ Serve outdated content if the backend is down - Probes or saint mode is required for this ‣ Serve sightly staled content while fresh versions are fetched
  • 23. Beyond caching policy ๏ Why restricting VCL / VMODs to implement the caching policy? ๏ Any logic modeled in VCL / VMODs is compiled, embedded & executed in the caching edger layer ‣ 1000x times faster than typical Java / PHP apps - Strong restrictions ‣ Accounting, paywalling, A/B testing…
  • 24. varnishtest ๏ Powerful Varnish-specific testing tool ‣ Mocked clients & backends executing / processing HTTP requests against real Varnish Cache Plus instances ‣ http://www.clock.co.uk/...varnishtest ๏ Essential when implementing complex VCL logic ๏ Easily integrable in any CI infrastructure
  • 25. FAQ ๏ When SSL support will be implemented? ‣ "[...] huge waste of time and effort to even think about it." ๏ When SPDY support will be implemented? ‣ "[...] Varnish is not speedy, Varnish is fast! [...]" ๏ What is the recommended value for this bizarre kernel / varnishd parameter I found in some random blog? ‣ Use Varnish Tuner + Fine tune based on necessity ‣ Pay attention to workspaces & syslog messages
  • 27. Overview ๏ Updated objects may be available before TTL expiration ‣ Purges ‣ Forced misses ‣ Bans ‣ Hash Two / Hash Ninja / …
  • 28. Purges Overview ๏ VCL ๏ Eagerly discards an object along with all its variants acl internal { "localhost"; "192.168.55.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (client.ip !~ internal) { error 405 "Not allowed."; } return (lookup); } } sub vcl_hit { if (req.request == "PURGE") { purge; error 200 "Purged."; } } sub vcl_miss { if (req.request == "PURGE") { purge; error 200 "Purged."; } }
  • 29. Purges Downsides I ๏ What if the new object cannot be fetched after the invalidation? ‣ Soft-purges VMOD ‣ Forces misses ๏ What if multiple objects need to be invalidated? What if objects need to be invalidated too frequently? ‣ Bans ‣ Hash Two
  • 30. Purges Downsides II ๏ How to invalidate hitpass objects? ‣ Not possible in Varnish Cache Plus 3.x - Redesigned in Varnish Cache Plus 4.x - https://www.varnish-cache.org/trac/.../1033 ‣ return(pass); during vcl_recv is preferred when possible
  • 31. Forced misses Overview ๏ VCL ๏ Forces a cache miss for the request ‣ Useful for cache priming scripts sub vcl_recv { if (req.http.X-­‐Priming-­‐Script) { ... set req.hash_always_miss = true; } ... }
  • 32. Forced misses Behavior ๏ Object will always be (re)fetched from the backend ๏ New object is put into cache and used from that point onward ‣ Old object is not evicted until it’s safe to do so ‣ Controls who takes the penalty of waiting for an updated object ๏ Old objects are not freed up until expiration ‣ This is considered a flaw and a fix is expected
  • 33. Bans Overview ๏ VCL or CLI ๏ Lazily discards multiple objects matching an expression ‣ Logical operators + Object attributes + Regular expressions ‣ Only works on objects already in the cache ๏ Ban lurker ‣ Frees up memory + Keeps the ban list at a manageable size ‣ obj.* based expressions
  • 34. Bans Example sub vcl_recv { if (req.request == "BAN") { ... if (!req.http.X-­‐Ban-­‐Url-­‐Regexp) { error 400 "Empty URL regexp."; } ban("obj.http.X-­‐Url ~ " + req.http.X-­‐Ban-­‐Url-­‐Regexp); } } sub vcl_fetch { set beresp.http.X-­‐Url = req.url; } sub vcl_deliver { unset resp.http.X-­‐Url; }
  • 35. Hash Two Overview ๏ VCL + VMOD ๏ Workarounds bans scalability HTTP/1.x 200 OK Transfer-­‐Encoding: chunked ... X-­‐Tags: C10 P42 P236 P857 ... ban obj.http.X-­‐Tags ~ "(s|^)P42(s|$)"
  • 36. Hash Two Example import hashtwo; sub vcl_recv { if (req.request == "PURGE") { ... if (hashtwo.purge(req.http.X-­‐Tag) != 0) { error 200 "Purged."; } else { error 404 "Not found."; } } } sub vcl_fetch { set beresp.http.X-­‐HashTwo = beresp.http.X-­‐Tags; }
  • 38. Cache related headers ๏ Expires ๏ Cache-Control ๏ Last-Modified ๏ If-Modified-Since ๏ If-None-Match ๏ Etag ๏ Pragma ๏ Vary ๏ Age
  • 39. Cache-Control Overview ๏ Specifies directives that must be applied by all caching mechanisms (from Varnish Cache Plus to browser cache) ‣ public | private ‣ no-­‐store ‣ no-­‐cache ‣ max-­‐age ‣ s-­‐maxage ‣ must-­‐revalidate ‣ no-­‐transform ‣ …
  • 40. Cache-Control beresp.ttl ๏ Ignored in incoming client HTTP requests ๏ Only s-­‐maxage & max-­‐age used in backend HTTP responses to calculate default TTL ‣ Always overrides Expires header ‣ Beware of Age header in client responses - Objects not cached client side - https://www.varnish-cache.org/...Caching
  • 41. Vary ๏ Indicates the response returned by the backend server may vary depending on headers received in the request ๏ Object variants & Hit ratio ‣ Vary: Accept-­‐Encoding - Normalization of Accept-­‐Encoding header is not required ‣ Vary: User-­‐Agent
  • 43. Overview ๏ Break objects into smaller fragments ‣ Separate cache policy for each fragment ‣ Increase hit ratio ๏ Tools ‣ Edge Side Includes (ESI) ‣ AJAX - Beware of RTT & Cross domain policy
  • 44. Edge Side Includes ๏ Subset of ESI Language Specification 1.0 ‣ <esi:include src="<URL> " /> ‣ <esi:remove>...</esi:remove> ‣ <!-­‐-­‐esi ...—> ๏ set beresp.do_esi = true; ‣ Separate Varnish requests ๏ Testing ESI in dev environment
  • 46. Overview ๏ Central control of Varnish Cache Plus servers ‣ Web UI + RESTful API - Super Fast Purger ๏ Cache group management ‣ Real time statistics, VCL editor, ban submission… ๏ Varnish Agent 2
  • 47.
  • 48.
  • 49. Super Fast Purger ๏ High performance intermediary distributing invalidation requests to groups of Varnish Cache Plus servers ‣ Leverages speed & flexibility of VCL ‣ Keep-alive workaround ๏ Part of the VAC RESTful API ‣ Trivially integrable in existing applications
  • 50. Change management ๏ Easily integrable using the VAC RESTful API ‣ git, Mercurial… hooks ‣ Jenkins, Travis, GitLab… CI scripts ๏ Manual VCL bundle generation ๏ Orchestrated / programmed deployments, rollbacks, etc.
  • 52. Overview ๏ Real-time aggregated statistics ‣ Multiple vstatdprobe daemons ‣ One vstatd daemon ‣ JSON + Time series API ๏ VSM log based ‣ Efficient circular in-memory data structure ‣ std.log("vcs-­‐key:" + <key suffix>);
  • 53. Some ideas ๏ Trending articles or sale products ๏ Cache hits and cache misses ๏ URLs with long load times ๏ URLs with the most 5xx response codes ๏ Where traffic is coming from ๏ …
  • 54. Example sub vcl_deliver { std.log("vcs-­‐key:" + req.http.host); std.log("vcs-­‐key:" + req.http.host + req.url); std.log("vcs-­‐key:TOTAL"); if (obj.hits == 0) { std.log("vcs-­‐key:MISS"); } }
  • 55. API I ๏ Stats (#requests, #misses, avg ttfb, acc body bytes, #2xx, #3xx…) for key named “example.com" during the last time windows ‣ GET /key/example.com ๏ Keys that produced the most 5xx responses during the last time window ‣ GET /all/top_5xx ๏ Top 5 requested keys during the last time window ‣ GET /all/top/5?verbose=1
  • 56. API II ๏ Top 10 most requested keys ending with ‘.gif' during the last time window ‣ GET /match/(.*)%5C.gif$/top ๏ Top 50 slowest backend requests aggregating the last 20 time windows ‣ GET /all/top_ttfb/50?b=20
  • 58. Overview ๏ VMOD ๏ DeviceAtlas ‣ https://deviceatlas.com ‣ Database locally deployed & Daily updated ๏ OSS alternatives ‣ https://github.com/serbanghita/Mobile-Detect ‣ …
  • 59. Example import deviceatlas; sub vcl_recv { if (deviceatlas.lookup(req.http.User-­‐Agent, "isMobilePhone") == "1") { set req.http.X-­‐Device = "mobile"; } elsif (deviceatlas.lookup(req.http.User-­‐Agent, "isTablet") == "1") { set req.http.X-­‐Device = "tablet"; } else { set req.http.X-­‐Device = "desktop"; } }
  • 60. Some ideas ๏ Redirections based on device properties ๏ Backend selection based on device properties ๏ Normalization of the UA header ‣ Caching different versions (i.e. Vary header) of the same object based on normalized UAs ๏ …
  • 62. Highlights ๏ Client / backend thread split ‣ Background content refreshing ๏ Redesigned purges ‣ return(purge); during vcl_recv ๏ Directors implemented as VMODs ‣ Consistent hashing director ๏ Distinction between error & synthetic responses