SlideShare une entreprise Scribd logo
1  sur  44
Télécharger pour lire hors ligne
Advanced cache
invalidation strategies for
high performance
websites
with Varnish Cache
Per Buer / CTO / Varnish Software
Phil Karlton
“There are only two hard things in
Computer Science: cache invalidation
and naming things.”
About Varnish Cache
● Web app accelerator
● Fast
● Flexible
About Varnish Software
● The company behind Varnish Cache
● Offers subscriptions with
○ Software
○ 24/7 support
○ Professional services
Goal
Run an efficient website with Varnish Cache
● Allows for longer TTLs
○ Higher cache hit ratios
○ Better UX
○ Lower backend usage
● Instantaneous updates when content
changes
Why do cache invalidation?
Components in Varnish
Components in Varnish we’ll be
covering
● PURGE
● ban
● Soft PURGE
● Soft Ban
● “Smart” bans
● Ban/purge distribution - VAC Super Fast
Purger
● Hashninja
● HTTP verb
● Takes URL as parameter
● Can purge all variants
● Derived from Squid
HTTP PURGE
PURGE /foo HTTP/1.1
Host: www.bar.com
HTTP PURGE
PURGE VCL
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
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.";
}
}
PURGE VCL
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
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.";
}
}
PURGE VCL
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
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.";
}
}
PURGE VCL
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
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.";
}
}
PURGE VCL
acl purge {
"localhost";
"192.168.55.0"/24;
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
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.";
}
}
● Fast
● Efficient
● Knows nothing about relationships between
pages
● Doesn’t know about grace
HTTP PURGE
Varnish bans
● Fast
● Flexible - can match almost any pattern
● Regular expressions on obj or req
● Not efficient
● Doesn’t know about grace
Varnish bans
CLI:
ban req.http.host == "example.com" &&
req.url ~ ".png$"
HTTP:
BAN /foo HTTP/1.1
Host: www.bar.com
Ban VCL
sub vcl_recv {
if (req.request == "BAN") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
ban("req.http.host == " + req.http.host +
"&& req.url == " + req.url);
# Throw a synthetic page so the
# request won't go to the backend.
error 200 "Ban added";
}
}
Ban list
Bans Objects in cache
Ban list
Bans Objects in cache
time = t0
Ban list
Bans Objects older than t0
time = t0
● Each object matched only
once against each ban.
● Potentially killed.
The ban lurker
Bans
Om nom nom nom nom
● Worker thread
● Evaluates each ban against
objects older than it
● Works only for bans on obj.*
● Kills a ban when it is
matched against all objects
older than t0.
Please do smart bans
● Avoid banning on req.*
● Copy the bits from req to beresp in vcl_fetch
● Keep an eye on the ban list and regex/sec
● Trim cache
Graceful
cache
invalidation
Graceful cache invalidation
● Problem: Purge object - backend goes
down. No graced objects left to serve.
● “There is VMOD for that!”
● Marks objects as stale instead of killing them
● https://www.varnish-cache.org/vmod/soft-
purge
What about graceful bans?
● Same as regular bans but objects are still
subject to grace
● Requires a patch for Varnish Cache which
might or might not make it into mainline
Advanced topics
Distribution of invalidation events
● You don’t want every webapp to know about
every varnish server
● Distribute invalidation events from a single
point
Distribution of invalidation events
varnishvarnish varnishvarnish
Distribution of invalidation events
varnishvarnish varnishvarnish
admin
Distribution of invalidation events
varnishvarnish varnishvarnish
admin
Simplest invalidation distributor
nc -l 2000 | while true
do read url
for srv in “alfa” “beta” “gamma”
do curl -m 2 -x $srv -X PURGE $url
done
done
VAC Fast purger
● Fast API for event distribution
● 40 Kreq/s across datacenters
curl -X POST –user user:pw -H ‘Content-Type: text/plain’
-d ‘req.url ~ “/articles/FOO”‘
http://vac.local/api/v1/cachegroup/production/ban
Invalidation based on content
relationship
● You have a web page with content from 8
different objects
● One object is updated
● Which pages to purge?
Content tagging in Varnish
● Add X-Keys to each object (SKUs, article
IDs or similar unique IDs)
● Identifies each object that is on the page
● Then you invalidate based on that unique ID.
● Every page that mentions that ID will be
invalidated
Banning based on tagged content
● ban obj.http.x-keys ~ “[ ,]$IDD”
● Suitable for low volume updates
● CPU usage will increase due to bans
● On high volumes you should check out….
Hashninja
● Maintains a hash with keys⇔pages
● Many-to-many
● Very low overhead, high performance
● Requires subscription + Proprietary VMOD
● Suited for e-commerce and digital media
Summing up
● Purges
● Bans
● Soft purges and bans
● Smart bans
● Hashninja and content tagging
Thanks!
Questions and comments, please.
Get in touch: per.buer@varnish-software.
com

Contenu connexe

Tendances

Web frameworks don't matter
Web frameworks don't matterWeb frameworks don't matter
Web frameworks don't matter
Tomas Doran
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
Joseph Scott
 
Pushing the web — WebSockets
Pushing the web — WebSocketsPushing the web — WebSockets
Pushing the web — WebSockets
Roland M
 
Xen_and_Rails_deployment
Xen_and_Rails_deploymentXen_and_Rails_deployment
Xen_and_Rails_deployment
Abhishek Singh
 

Tendances (20)

WordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngineWordPress + NGINX Best Practices with EasyEngine
WordPress + NGINX Best Practices with EasyEngine
 
WebSockets and Java
WebSockets and JavaWebSockets and Java
WebSockets and Java
 
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
 
Web frameworks don't matter
Web frameworks don't matterWeb frameworks don't matter
Web frameworks don't matter
 
Networking fundamentals
Networking fundamentalsNetworking fundamentals
Networking fundamentals
 
Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014
 
Revisiting HTTP/2
Revisiting HTTP/2Revisiting HTTP/2
Revisiting HTTP/2
 
Varnish 4 cool features
Varnish 4 cool featuresVarnish 4 cool features
Varnish 4 cool features
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
 
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
 
Pushing the web — WebSockets
Pushing the web — WebSocketsPushing the web — WebSockets
Pushing the web — WebSockets
 
TLS - 2016 Velocity Training
TLS - 2016 Velocity TrainingTLS - 2016 Velocity Training
TLS - 2016 Velocity Training
 
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
 
ReplacingSquidWithATS
ReplacingSquidWithATSReplacingSquidWithATS
ReplacingSquidWithATS
 
HAProxy scale out using open source
HAProxy scale out using open sourceHAProxy scale out using open source
HAProxy scale out using open source
 
Altitude SF 2017: Debugging Fastly VCL 101
Altitude SF 2017: Debugging Fastly VCL 101Altitude SF 2017: Debugging Fastly VCL 101
Altitude SF 2017: Debugging Fastly VCL 101
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
 
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...
 
Rails hosting
Rails hostingRails hosting
Rails hosting
 
Xen_and_Rails_deployment
Xen_and_Rails_deploymentXen_and_Rails_deployment
Xen_and_Rails_deployment
 

Similaire à Advanced cache invalidation

Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
schoefmax
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with Varnish
AOE
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101
ConFoo
 

Similaire à Advanced cache invalidation (20)

Altitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and ClusteringAltitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and Clustering
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Varnish
VarnishVarnish
Varnish
 
Vagrant introduction for Developers
Vagrant introduction for DevelopersVagrant introduction for Developers
Vagrant introduction for Developers
 
Varnish qconsp 2011
Varnish qconsp 2011Varnish qconsp 2011
Varnish qconsp 2011
 
Caching with Varnish
Caching with VarnishCaching with Varnish
Caching with Varnish
 
T3DD12 Caching with Varnish
T3DD12 Caching with VarnishT3DD12 Caching with Varnish
T3DD12 Caching with Varnish
 
Deploying And Monitoring Rails
Deploying And Monitoring RailsDeploying And Monitoring Rails
Deploying And Monitoring Rails
 
Setting up automated tasks
Setting up automated tasksSetting up automated tasks
Setting up automated tasks
 
Nginx + PHP
Nginx + PHPNginx + PHP
Nginx + PHP
 
Vagrant-Overview
Vagrant-OverviewVagrant-Overview
Vagrant-Overview
 
Varnish e caching di applicazioni Rails
Varnish e caching di applicazioni RailsVarnish e caching di applicazioni Rails
Varnish e caching di applicazioni Rails
 
Denser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microserversDenser, cooler, faster, stronger: PHP on ARM microservers
Denser, cooler, faster, stronger: PHP on ARM microservers
 
Resin Outperforms NginX
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginX
 
Use Xdebug to profile PHP
Use Xdebug to profile PHPUse Xdebug to profile PHP
Use Xdebug to profile PHP
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101
 
Varnish - PLNOG 4
Varnish - PLNOG 4Varnish - PLNOG 4
Varnish - PLNOG 4
 
Load Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINXLoad Balancing and Scaling with NGINX
Load Balancing and Scaling with NGINX
 
Debugging your varnish instance
Debugging your varnish instanceDebugging your varnish instance
Debugging your varnish instance
 
Instant scaling and deployment of Vitis Libraries on Alveo clusters using InA...
Instant scaling and deployment of Vitis Libraries on Alveo clusters using InA...Instant scaling and deployment of Vitis Libraries on Alveo clusters using InA...
Instant scaling and deployment of Vitis Libraries on Alveo clusters using InA...
 

Plus de Per Buer (6)

IncludeOS for ics 2018
IncludeOS for ics 2018IncludeOS for ics 2018
IncludeOS for ics 2018
 
Include os @ flossuk 2018
Include os @ flossuk 2018Include os @ flossuk 2018
Include os @ flossuk 2018
 
Tuning the Kernel for Varnish Cache
Tuning the Kernel for Varnish CacheTuning the Kernel for Varnish Cache
Tuning the Kernel for Varnish Cache
 
Varnish Cache 4.0 / Redpill Linpro breakfast in Oslo
Varnish Cache 4.0 / Redpill Linpro breakfast in OsloVarnish Cache 4.0 / Redpill Linpro breakfast in Oslo
Varnish Cache 4.0 / Redpill Linpro breakfast in Oslo
 
Varnish Cache - step by step
Varnish Cache - step by stepVarnish Cache - step by step
Varnish Cache - step by step
 
Hard parts paywall - stup
Hard parts   paywall - stupHard parts   paywall - stup
Hard parts paywall - stup
 

Dernier

Dernier (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Advanced cache invalidation

  • 1. Advanced cache invalidation strategies for high performance websites with Varnish Cache Per Buer / CTO / Varnish Software
  • 2. Phil Karlton “There are only two hard things in Computer Science: cache invalidation and naming things.”
  • 3. About Varnish Cache ● Web app accelerator ● Fast ● Flexible
  • 4.
  • 5. About Varnish Software ● The company behind Varnish Cache ● Offers subscriptions with ○ Software ○ 24/7 support ○ Professional services
  • 6. Goal Run an efficient website with Varnish Cache
  • 7. ● Allows for longer TTLs ○ Higher cache hit ratios ○ Better UX ○ Lower backend usage ● Instantaneous updates when content changes Why do cache invalidation?
  • 8.
  • 10. Components in Varnish we’ll be covering ● PURGE ● ban ● Soft PURGE ● Soft Ban ● “Smart” bans ● Ban/purge distribution - VAC Super Fast Purger ● Hashninja
  • 11. ● HTTP verb ● Takes URL as parameter ● Can purge all variants ● Derived from Squid HTTP PURGE
  • 12. PURGE /foo HTTP/1.1 Host: www.bar.com HTTP PURGE
  • 13. PURGE VCL acl purge { "localhost"; "192.168.55.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { 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."; } }
  • 14. PURGE VCL acl purge { "localhost"; "192.168.55.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { 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."; } }
  • 15. PURGE VCL acl purge { "localhost"; "192.168.55.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { 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."; } }
  • 16. PURGE VCL acl purge { "localhost"; "192.168.55.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { 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."; } }
  • 17. PURGE VCL acl purge { "localhost"; "192.168.55.0"/24; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge) { 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."; } }
  • 18. ● Fast ● Efficient ● Knows nothing about relationships between pages ● Doesn’t know about grace HTTP PURGE
  • 19. Varnish bans ● Fast ● Flexible - can match almost any pattern ● Regular expressions on obj or req ● Not efficient ● Doesn’t know about grace
  • 20. Varnish bans CLI: ban req.http.host == "example.com" && req.url ~ ".png$" HTTP: BAN /foo HTTP/1.1 Host: www.bar.com
  • 21. Ban VCL sub vcl_recv { if (req.request == "BAN") { if (!client.ip ~ purge) { error 405 "Not allowed."; } ban("req.http.host == " + req.http.host + "&& req.url == " + req.url); # Throw a synthetic page so the # request won't go to the backend. error 200 "Ban added"; } }
  • 23. Ban list Bans Objects in cache time = t0
  • 24. Ban list Bans Objects older than t0 time = t0 ● Each object matched only once against each ban. ● Potentially killed.
  • 25. The ban lurker Bans Om nom nom nom nom ● Worker thread ● Evaluates each ban against objects older than it ● Works only for bans on obj.* ● Kills a ban when it is matched against all objects older than t0.
  • 26. Please do smart bans ● Avoid banning on req.* ● Copy the bits from req to beresp in vcl_fetch ● Keep an eye on the ban list and regex/sec ● Trim cache
  • 28. Graceful cache invalidation ● Problem: Purge object - backend goes down. No graced objects left to serve. ● “There is VMOD for that!” ● Marks objects as stale instead of killing them ● https://www.varnish-cache.org/vmod/soft- purge
  • 29. What about graceful bans? ● Same as regular bans but objects are still subject to grace ● Requires a patch for Varnish Cache which might or might not make it into mainline
  • 31. Distribution of invalidation events ● You don’t want every webapp to know about every varnish server ● Distribute invalidation events from a single point
  • 32. Distribution of invalidation events varnishvarnish varnishvarnish
  • 33. Distribution of invalidation events varnishvarnish varnishvarnish admin
  • 34. Distribution of invalidation events varnishvarnish varnishvarnish admin
  • 35. Simplest invalidation distributor nc -l 2000 | while true do read url for srv in “alfa” “beta” “gamma” do curl -m 2 -x $srv -X PURGE $url done done
  • 36. VAC Fast purger ● Fast API for event distribution ● 40 Kreq/s across datacenters curl -X POST –user user:pw -H ‘Content-Type: text/plain’ -d ‘req.url ~ “/articles/FOO”‘ http://vac.local/api/v1/cachegroup/production/ban
  • 37. Invalidation based on content relationship ● You have a web page with content from 8 different objects ● One object is updated ● Which pages to purge?
  • 38.
  • 39. Content tagging in Varnish ● Add X-Keys to each object (SKUs, article IDs or similar unique IDs) ● Identifies each object that is on the page ● Then you invalidate based on that unique ID. ● Every page that mentions that ID will be invalidated
  • 40. Banning based on tagged content ● ban obj.http.x-keys ~ “[ ,]$IDD” ● Suitable for low volume updates ● CPU usage will increase due to bans ● On high volumes you should check out….
  • 41.
  • 42. Hashninja ● Maintains a hash with keys⇔pages ● Many-to-many ● Very low overhead, high performance ● Requires subscription + Proprietary VMOD ● Suited for e-commerce and digital media
  • 43. Summing up ● Purges ● Bans ● Soft purges and bans ● Smart bans ● Hashninja and content tagging
  • 44. Thanks! Questions and comments, please. Get in touch: per.buer@varnish-software. com