SlideShare a Scribd company logo
1
Do you
speak VCL?
2
The Varnish Book
Dedicated writer and
maintainer
Francisco Velázquez
Curriculum Manager
francisco@varnish-software.com
CDNs with Varnish
Build your own CDN with
Varnish
Who am I?
Agenda
● What is VCL?
● Motivate from learning VCL
● Understanding VCL in Varnish
● VCL as finite state machine
● How to design and test your VCL code?
● VCL tips and tricks
● Typical mistakes in VCL
● Conclusions
4
What is
VCL?
5
Varnish Configuration Language (VCL)
● VCL is a domain specific
language based on C
● Programming language
specialized to express solutions
for caching the Web
● Rule-based language
6
Why should you program in VCL?
● Varnish covers most common caching needs out-of-the-box, but
does not intend to be a one-fit-all solution!
● VCL allows you to:
○ define your own rules
○ specify when to use and alternate them on run time
7
Cacher
Web Application Firewall
Hotlinking Protector
DDoS Attack Defender
Load Balancer
Authentication and
Authorization Mechanism
HTTP Router
and more...
VCL makes Varnish to act as:
VCL
8
VCL Characteristics (1/2)
● Simple syntax, but pay attention to the semantics of HTTP
● No loops
● Functionality grouped in subroutines that
○ do not take arguments nor return values
○ exchange data only through HTTP headers
● VCL can manipulate HTTP headers
○ Override TTLs
○ Strip cookies
○ Rewrite URLs
● Extensible via Varnish modules (VMODs)
9
VCL Characteristics (2/2)
● Load multiple VCLs and switch between them instantly and seamlessly
● No server restart required
● Includes built-in functions that allow you to:
○ modify strings
○ invalidate caches
● Supports regular expressions (regex)
● Languages evolve, so VCL does!
○ varnish3to4 script
10
Varnish Finite State
Machine (FSM)
● States in Varnish FSM are per HTTP
request
○ HTTP is a stateless protocol
● State preservation across
transactions use mechanisms such
as cookies
11
Built-in VCL
subroutines per state
● File location: varnish-cache/bin/varnishd/builtin.vcl
12
Your VCL code *always*
precedes the built-in VCL
code!
13
Your VCL code
Built-in VCL code
14
Understanding how VCL works in Varnish
varnishd
VCC Process
Manager
Process
CLI
...
Cacher
Process
Storage
...
Shared Memory
Log
C-compiler Shared Object
One
binary
program
VAC
varnishadm
varnishlog
...
15
How to design your VCL code?
● Design your rules first
○ Create Varnish Test Cases (VTC) in varnishtest
○ Attend to Arianna’s presentation after break
● Be sure you understand the HTTP caching headers and objects’ lifetime
○ Refer to The Varnish Book
○ Refer to RFC7232 and RFC7234
● Get ideas from VCL snippets you find in Internet, but be critical!
● Test your VCL!
○ Use varnishtest
16
● Design a plan for
cache invalidation
Source: https://www.posterlounge.co.uk/spiderman-
pr28529.html
17
Cache Invalidation Alternatives
Bans Purge Soft Purge Hashtwo –
Surrogate keys
Force Cache
Misses
Targets Patterns matching Specific object Specific object Objects with
common key
Specific object
Frees
memory
After a request hits an
object or the ban luker
invalidates cached object
Immediately After grace
time
Immediately No
Scalability High High High High Low
VCL Yes Yes Yes Yes Yes
CLI Yes No No No No
Table 18 in The Varnish Book 18
VCL tips and tricks
● Command to print VCL code compiled to C language and exit:
○ $ varnishd -C -f filename
○ Useful to check whether your VCL code compiles correctly
● Data types:
○ TIME + DURATION is allowed
○ TIME - TIME = DURATION is allowed
○ TIME + TIME is not allowed!
○ Use the Varnish Standard Module (std VMOD)
○ If not in std VMOD, do not assume automatic data type conversions, test
them!
● Check operator precedence and more at varnish-cache.org
19
Typical
mistakes20
Typical Mistakes in VCL (1/3)
● Regular expressions
● Cache with inefficient cache invalidation plan
● Skipping the built-in VCL by calling return(action)
○ Caching cookies inadvertently
● Order query parameters of a URL
○ example.com/test?var0=0&var1=1
○ example.com/test?var1=1&var0=0
○ Call querysort(STRING) from std VMOD
● Copy/paste VCL snippets without understanding them
21
Typical Mistakes in VCL (2/3)
● Create uncontrolled variations of hash key values for the same object
○ Vary: User-Agent
○ Vary: Cookie
22
Typical Mistakes in VCL (3/3)
● Understand request serialization and the hit-for-pass object
● Let vcl_backend_response execute!
○ Otherwise, never set beresp.ttl = 0
○ Slows down site response if skipped
● Varnish 3 has a hit_for_pass return action
● Varnish 4 beresp.uncacheable = true;
23
Ask for Help and Share
● Contact Varnish Support
● IRC channel #varnish on irc.linpro.net
● Mailing lists: https://www.varnish-cache.org/trac/wiki/MailingLists
● Consult The Varnish Book
● https://www.varnish-cache.org/trac/wiki/VCLExamples
● https://www.varnish-cache.org/docs/4.0/reference/vcl.html
24
Take away points
● It is worth it to learn VCL
● VCL has a simple syntax
● Design Varnish Test Cases and test your VCL in varnishtest
● Let the built-in VCL code execute!
25

More Related Content

Similar to Do you speak vcl

9th docker meetup 2016.07.13
9th docker meetup 2016.07.139th docker meetup 2016.07.13
9th docker meetup 2016.07.13
Amrita Prasad
 
from Docker to Moby and back. what changed ?
from Docker to Moby and back. what changed ?from Docker to Moby and back. what changed ?
from Docker to Moby and back. what changed ?
strikr .
 
Varnish e caching di applicazioni Rails
Varnish e caching di applicazioni RailsVarnish e caching di applicazioni Rails
Varnish e caching di applicazioni Rails
Antonio Carpentieri
 
RSA SF Conference talk-2009-ht2-401 sallam
RSA SF Conference talk-2009-ht2-401 sallamRSA SF Conference talk-2009-ht2-401 sallam
RSA SF Conference talk-2009-ht2-401 sallam
Ahmed Sallam
 
Chromium: NaCl and Pepper API
Chromium: NaCl and Pepper APIChromium: NaCl and Pepper API
Chromium: NaCl and Pepper API
Chang W. Doh
 
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
NETWAYS
 
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
CTruncer
 
Windows 8 javascript apps – getting it right
Windows 8 javascript apps – getting it rightWindows 8 javascript apps – getting it right
Windows 8 javascript apps – getting it right
brendankowitz
 
Introduction to Varnish VCL
Introduction to Varnish VCLIntroduction to Varnish VCL
Introduction to Varnish VCL
Pax Dickinson
 
Key considerations for multithreaded architectures in LabVIEW
Key considerations for multithreaded architectures in LabVIEWKey considerations for multithreaded architectures in LabVIEW
Key considerations for multithreaded architectures in LabVIEW
Piotr Demski
 
Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...
Black Duck by Synopsys
 
Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...
Tim Mackey
 
Surviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-studySurviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-study
peter_ibuildings
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
Abid Malik
 
Varnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developersVarnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developers
Carlos Abalde
 
Webinar: From Development to Production with Docker and MongoDB
Webinar: From Development to Production with Docker and MongoDBWebinar: From Development to Production with Docker and MongoDB
Webinar: From Development to Production with Docker and MongoDB
MongoDB
 
Vb.net session 15
Vb.net session 15Vb.net session 15
Vb.net session 15
Niit Care
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
Mahbub E Elahi (Ron)
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
OdessaJS Conf
 
Developer Special: How to Prepare Applications for Notes 64-bit Clients
Developer Special: How to Prepare Applications for Notes 64-bit ClientsDeveloper Special: How to Prepare Applications for Notes 64-bit Clients
Developer Special: How to Prepare Applications for Notes 64-bit Clients
panagenda
 

Similar to Do you speak vcl (20)

9th docker meetup 2016.07.13
9th docker meetup 2016.07.139th docker meetup 2016.07.13
9th docker meetup 2016.07.13
 
from Docker to Moby and back. what changed ?
from Docker to Moby and back. what changed ?from Docker to Moby and back. what changed ?
from Docker to Moby and back. what changed ?
 
Varnish e caching di applicazioni Rails
Varnish e caching di applicazioni RailsVarnish e caching di applicazioni Rails
Varnish e caching di applicazioni Rails
 
RSA SF Conference talk-2009-ht2-401 sallam
RSA SF Conference talk-2009-ht2-401 sallamRSA SF Conference talk-2009-ht2-401 sallam
RSA SF Conference talk-2009-ht2-401 sallam
 
Chromium: NaCl and Pepper API
Chromium: NaCl and Pepper APIChromium: NaCl and Pepper API
Chromium: NaCl and Pepper API
 
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
stackconf 2020 | Replace your Docker based Containers with Cri-o Kata Contain...
 
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
 
Windows 8 javascript apps – getting it right
Windows 8 javascript apps – getting it rightWindows 8 javascript apps – getting it right
Windows 8 javascript apps – getting it right
 
Introduction to Varnish VCL
Introduction to Varnish VCLIntroduction to Varnish VCL
Introduction to Varnish VCL
 
Key considerations for multithreaded architectures in LabVIEW
Key considerations for multithreaded architectures in LabVIEWKey considerations for multithreaded architectures in LabVIEW
Key considerations for multithreaded architectures in LabVIEW
 
Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...
 
Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...Using hypervisor and container technology to increase datacenter security pos...
Using hypervisor and container technology to increase datacenter security pos...
 
Surviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-studySurviving a Plane Crash, a NU.nl case-study
Surviving a Plane Crash, a NU.nl case-study
 
IDE and Toolset For Magento Development
IDE and Toolset For Magento DevelopmentIDE and Toolset For Magento Development
IDE and Toolset For Magento Development
 
Varnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developersVarnish Cache Plus. Random notes for wise web developers
Varnish Cache Plus. Random notes for wise web developers
 
Webinar: From Development to Production with Docker and MongoDB
Webinar: From Development to Production with Docker and MongoDBWebinar: From Development to Production with Docker and MongoDB
Webinar: From Development to Production with Docker and MongoDB
 
Vb.net session 15
Vb.net session 15Vb.net session 15
Vb.net session 15
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
 
Developer Special: How to Prepare Applications for Notes 64-bit Clients
Developer Special: How to Prepare Applications for Notes 64-bit ClientsDeveloper Special: How to Prepare Applications for Notes 64-bit Clients
Developer Special: How to Prepare Applications for Notes 64-bit Clients
 

More from Varnish Software

Ask Me Anything on authentication & authorisation in Varnish
Ask Me Anything on authentication & authorisation in VarnishAsk Me Anything on authentication & authorisation in Varnish
Ask Me Anything on authentication & authorisation in Varnish
Varnish Software
 
Boozt.com Use Case
Boozt.com Use CaseBoozt.com Use Case
Boozt.com Use Case
Varnish Software
 
Akamai connector for varnish
Akamai connector for varnishAkamai connector for varnish
Akamai connector for varnish
Varnish Software
 
Varnish High Availability
Varnish High AvailabilityVarnish High Availability
Varnish High Availability
Varnish Software
 
PostNord: Copy On Write
PostNord: Copy On WritePostNord: Copy On Write
PostNord: Copy On Write
Varnish Software
 
Varnish extend
Varnish extendVarnish extend
Varnish extend
Varnish Software
 
Streaming with Varnish
Streaming with VarnishStreaming with Varnish
Streaming with Varnish
Varnish Software
 
Edgestash
EdgestashEdgestash
Edgestash
Varnish Software
 
What is new in varnish plus
What is new in varnish plusWhat is new in varnish plus
What is new in varnish plus
Varnish Software
 
Varnish Extend demo
Varnish Extend demoVarnish Extend demo
Varnish Extend demo
Varnish Software
 
Varnish extend introduction
Varnish extend introductionVarnish extend introduction
Varnish extend introduction
Varnish Software
 
Cedexis introduction
Cedexis introductionCedexis introduction
Cedexis introduction
Varnish Software
 
Secure content caching
Secure content cachingSecure content caching
Secure content caching
Varnish Software
 
Microservices
MicroservicesMicroservices
Microservices
Varnish Software
 
Varnishtest
VarnishtestVarnishtest
Varnishtest
Varnish Software
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with Varnish
Varnish Software
 
E-commerce use case
E-commerce use caseE-commerce use case
E-commerce use case
Varnish Software
 
Access control
Access controlAccess control
Access control
Varnish Software
 
Varnish TLS
Varnish TLSVarnish TLS
Varnish TLS
Varnish Software
 
MSE
MSEMSE

More from Varnish Software (20)

Ask Me Anything on authentication & authorisation in Varnish
Ask Me Anything on authentication & authorisation in VarnishAsk Me Anything on authentication & authorisation in Varnish
Ask Me Anything on authentication & authorisation in Varnish
 
Boozt.com Use Case
Boozt.com Use CaseBoozt.com Use Case
Boozt.com Use Case
 
Akamai connector for varnish
Akamai connector for varnishAkamai connector for varnish
Akamai connector for varnish
 
Varnish High Availability
Varnish High AvailabilityVarnish High Availability
Varnish High Availability
 
PostNord: Copy On Write
PostNord: Copy On WritePostNord: Copy On Write
PostNord: Copy On Write
 
Varnish extend
Varnish extendVarnish extend
Varnish extend
 
Streaming with Varnish
Streaming with VarnishStreaming with Varnish
Streaming with Varnish
 
Edgestash
EdgestashEdgestash
Edgestash
 
What is new in varnish plus
What is new in varnish plusWhat is new in varnish plus
What is new in varnish plus
 
Varnish Extend demo
Varnish Extend demoVarnish Extend demo
Varnish Extend demo
 
Varnish extend introduction
Varnish extend introductionVarnish extend introduction
Varnish extend introduction
 
Cedexis introduction
Cedexis introductionCedexis introduction
Cedexis introduction
 
Secure content caching
Secure content cachingSecure content caching
Secure content caching
 
Microservices
MicroservicesMicroservices
Microservices
 
Varnishtest
VarnishtestVarnishtest
Varnishtest
 
Lightning fast with Varnish
Lightning fast with VarnishLightning fast with Varnish
Lightning fast with Varnish
 
E-commerce use case
E-commerce use caseE-commerce use case
E-commerce use case
 
Access control
Access controlAccess control
Access control
 
Varnish TLS
Varnish TLSVarnish TLS
Varnish TLS
 
MSE
MSEMSE
MSE
 

Recently uploaded

GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 

Recently uploaded (20)

GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 

Do you speak vcl

  • 1. 1
  • 3. The Varnish Book Dedicated writer and maintainer Francisco Velázquez Curriculum Manager francisco@varnish-software.com CDNs with Varnish Build your own CDN with Varnish Who am I?
  • 4. Agenda ● What is VCL? ● Motivate from learning VCL ● Understanding VCL in Varnish ● VCL as finite state machine ● How to design and test your VCL code? ● VCL tips and tricks ● Typical mistakes in VCL ● Conclusions 4
  • 6. Varnish Configuration Language (VCL) ● VCL is a domain specific language based on C ● Programming language specialized to express solutions for caching the Web ● Rule-based language 6
  • 7. Why should you program in VCL? ● Varnish covers most common caching needs out-of-the-box, but does not intend to be a one-fit-all solution! ● VCL allows you to: ○ define your own rules ○ specify when to use and alternate them on run time 7
  • 8. Cacher Web Application Firewall Hotlinking Protector DDoS Attack Defender Load Balancer Authentication and Authorization Mechanism HTTP Router and more... VCL makes Varnish to act as: VCL 8
  • 9. VCL Characteristics (1/2) ● Simple syntax, but pay attention to the semantics of HTTP ● No loops ● Functionality grouped in subroutines that ○ do not take arguments nor return values ○ exchange data only through HTTP headers ● VCL can manipulate HTTP headers ○ Override TTLs ○ Strip cookies ○ Rewrite URLs ● Extensible via Varnish modules (VMODs) 9
  • 10. VCL Characteristics (2/2) ● Load multiple VCLs and switch between them instantly and seamlessly ● No server restart required ● Includes built-in functions that allow you to: ○ modify strings ○ invalidate caches ● Supports regular expressions (regex) ● Languages evolve, so VCL does! ○ varnish3to4 script 10
  • 11. Varnish Finite State Machine (FSM) ● States in Varnish FSM are per HTTP request ○ HTTP is a stateless protocol ● State preservation across transactions use mechanisms such as cookies 11
  • 12. Built-in VCL subroutines per state ● File location: varnish-cache/bin/varnishd/builtin.vcl 12
  • 13. Your VCL code *always* precedes the built-in VCL code! 13
  • 14. Your VCL code Built-in VCL code 14
  • 15. Understanding how VCL works in Varnish varnishd VCC Process Manager Process CLI ... Cacher Process Storage ... Shared Memory Log C-compiler Shared Object One binary program VAC varnishadm varnishlog ... 15
  • 16. How to design your VCL code? ● Design your rules first ○ Create Varnish Test Cases (VTC) in varnishtest ○ Attend to Arianna’s presentation after break ● Be sure you understand the HTTP caching headers and objects’ lifetime ○ Refer to The Varnish Book ○ Refer to RFC7232 and RFC7234 ● Get ideas from VCL snippets you find in Internet, but be critical! ● Test your VCL! ○ Use varnishtest 16
  • 17. ● Design a plan for cache invalidation Source: https://www.posterlounge.co.uk/spiderman- pr28529.html 17
  • 18. Cache Invalidation Alternatives Bans Purge Soft Purge Hashtwo – Surrogate keys Force Cache Misses Targets Patterns matching Specific object Specific object Objects with common key Specific object Frees memory After a request hits an object or the ban luker invalidates cached object Immediately After grace time Immediately No Scalability High High High High Low VCL Yes Yes Yes Yes Yes CLI Yes No No No No Table 18 in The Varnish Book 18
  • 19. VCL tips and tricks ● Command to print VCL code compiled to C language and exit: ○ $ varnishd -C -f filename ○ Useful to check whether your VCL code compiles correctly ● Data types: ○ TIME + DURATION is allowed ○ TIME - TIME = DURATION is allowed ○ TIME + TIME is not allowed! ○ Use the Varnish Standard Module (std VMOD) ○ If not in std VMOD, do not assume automatic data type conversions, test them! ● Check operator precedence and more at varnish-cache.org 19
  • 21. Typical Mistakes in VCL (1/3) ● Regular expressions ● Cache with inefficient cache invalidation plan ● Skipping the built-in VCL by calling return(action) ○ Caching cookies inadvertently ● Order query parameters of a URL ○ example.com/test?var0=0&var1=1 ○ example.com/test?var1=1&var0=0 ○ Call querysort(STRING) from std VMOD ● Copy/paste VCL snippets without understanding them 21
  • 22. Typical Mistakes in VCL (2/3) ● Create uncontrolled variations of hash key values for the same object ○ Vary: User-Agent ○ Vary: Cookie 22
  • 23. Typical Mistakes in VCL (3/3) ● Understand request serialization and the hit-for-pass object ● Let vcl_backend_response execute! ○ Otherwise, never set beresp.ttl = 0 ○ Slows down site response if skipped ● Varnish 3 has a hit_for_pass return action ● Varnish 4 beresp.uncacheable = true; 23
  • 24. Ask for Help and Share ● Contact Varnish Support ● IRC channel #varnish on irc.linpro.net ● Mailing lists: https://www.varnish-cache.org/trac/wiki/MailingLists ● Consult The Varnish Book ● https://www.varnish-cache.org/trac/wiki/VCLExamples ● https://www.varnish-cache.org/docs/4.0/reference/vcl.html 24
  • 25. Take away points ● It is worth it to learn VCL ● VCL has a simple syntax ● Design Varnish Test Cases and test your VCL in varnishtest ● Let the built-in VCL code execute! 25