SlideShare a Scribd company logo
Varnish the Drupal Way
About me
• Boyan Borisov
• Team Leader @
Propeople
• boyanb@propeople.dk
• @boyan_borisov
• Skype: boian.borisov
• http://linkedin.com/in/
boyanborisov
What is Varnish?
• Reverse proxy cache server
• ... and more (load balancer, filter, director, ...)
• Open Source (BSD), commercially supported
• Typically in front of a LAMP stack
Why do we need Varnish?
• Believe or not Drupal is not very fast by
default ;)
• “Large Scale Drupal” is not only a sales phrase
but the present and the future of Drupal
• May be this is the best and fastest way to
achieve great performance results
Why do we need Varnish?
What does Varnish do?
What can be cached?
• Drupal pages for anonymous users
• Static content: images, js, css
• Other types of static or generated content
• Varnish stores a cache entry for each Host +
URL
What should NOT be cached in
Varnish?
• Responses to POST requests
• Responses with a Set-Cookie : header
• User-specific content (logged-in page
requests)
• Very large media files (> 100MB)
• Has a Cache-Control: no-cache header
When the cache will expire?
• Response header: Cache-Control: max-age=
300
• If no Cache-Control specified then Varnish
uses the Expires date, if specified
• If no Cache-Control or Expires header then
uses Varnish's default TTL which is 2 minutes
but could be changed
But wait… what about Drupal?
• Install varnish
• Install and configure the Drupal varnish module -
https://drupal.org/project/varnish
• Update the default Varnish VCL configuration
with a Drupal related one
– https://github.com/boyanborisov/varnish-for-drupal
– https://fourkitchens.atlassian.net/wiki/display/TECH/
Configure+Varnish+3+for+Drupal+7
– https://drupal.org/node/1427486
• And don’t forget to enable the caching for the
anonymous users
Varnish state machine
VCL – Varnish Configuration Language
• Extend and modify Varnish cache policies
• Add behaviors during each phase of delivery
• Each Request is processed separately and
independently
• States are isolated but are related
• Return statements exit one state and start
another
• VCL defaults are ALWAYS appended below your
own VCL
Other VCL features
• Add/remove/change HTTP headers
• Redirects based on request parameters
• Rewrite requests
• Retry failed requests
• Saint and Grace: Deliver cached content when backend
is unresponsive
• ACLs: Network-address filtering
• Request filtering ESI: Separate cache entries and
separate cache policies for each part of a document
• Inline C code
VCL – Subroutines – breaking it down
• vcl_init – VCL is loaded, no request yet; VMOD initialization
• vcl_recv – Beginning of request, req is in scope
• vcl_pipe – Client & backend data passed unaltered
• vcl_pass – Request goes to backend and not cached
• vcl_hash – call hash_data to add to the hash
• vcl_hit – called on request found in the cache
• vcl_miss – called on request not found in the cache
• vcl_fetch – called on document retrieved from backend
• vcl_deliver – called prior to delivery of cached object
• vcl_error – called on errors
Directors
• Directors allow you to talk to the backend servers
• Directors are a glorified reverse proxy
– Allows for certain types of load balancing
– Allows for talking to a cluster
“A director is a logical group of backend servers
clustered together for redundancy. The basic role of
the director is to let Varnish choose a backend
server amongst several so if one is down another
can be used.”
Varnish realtime tools
• varnishstat – realtime status and performance
metrics
• varnishhist – live frequency plot of response
times
• varnishtop – live list of hottest files
• varnishlog – analyze incoming HTTP headers
• Varnish CLI – live admin capabilities
Drupal specifics
• Drupal emits Vary – Cookie,Accept-Encoding
• Cookie – Avoids cache collisions between
users Accept-Encoding : maintain separate
cache entries for compressed content (gzip,
deflate) vs. uncompressed content
ESI – Edge Side Includes
• ESI is a small markup language much like SSI
(server side includes) to include fragments (or
dynamic content for that matter)
• Think of it as replacing regions inside of a page as
if you were using XHR (AJAX) but single threaded.
• Three Statements can be utilized
– esi:include – Include a page
– esi:remove – Remove content
– <!-- esi --> - ESI disabled, execute normally
How to cache authenticated users?
• Authcache - https://drupal.org/project/authcache
“Authcache saves the final rendered HTML of a page to serve visitors.
A separate cache is created for each user role as defined by the
administrator, so some roles can be excluded if necessary.
Authcache places priority on serving pages to the visitor as fast as
possible. After a page is loaded by the browser, a second HTTP request
may be performed via Ajax. This initiates a lightweight
DRUPAL_BOOTSTRAP_SESSION that allows SQL queries to be executed
, and returns any user-customized data to the page (such as form
tokens or default values on a contact form).”
How to cache authenticated users?
How to cache authenticated users?
How to cache authenticated users?
“Production graphs from intranet solution
developed by Propeople ( around 50 000 users ).
Web CPU usage below 1% and varnish hit ratio >
80%. Varnish & Propeople rocks  ”
Rumen Yordanov
Open Source Department manager @Propeople
Cache invalidation
• Drupal invalidate the whole Varnish cache on
node/comment/etc save by default
• Expire module is a solution -
https://drupal.org/project/expire
Purging and banning
• Purging – a purge is what happens when you pick out
an object from the cache and discard it along with its
variants. Usually a purge is invoked through HTTP with
the method PURGE.
• Banning – You can think of bans as a sort of a filter on
objects already in the cache. You ban certain content
from being served from your cache. You can ban
content based on any metadata we have. A ban will
only work on objects already in the cache, it does not
prevent new content from entering the cache or being
served.
Demo
Questions?

More Related Content

PDF
Caching with Varnish
PDF
Varnish http accelerator
PDF
Varnish - PLNOG 4
PDF
Varnish Configuration Step by Step
PPTX
Drupal, varnish, esi - Toulouse November 2
PPTX
cache concepts and varnish-cache
PDF
Memcached Code Camp 2009
PDF
Moxi - Memcached Proxy
Caching with Varnish
Varnish http accelerator
Varnish - PLNOG 4
Varnish Configuration Step by Step
Drupal, varnish, esi - Toulouse November 2
cache concepts and varnish-cache
Memcached Code Camp 2009
Moxi - Memcached Proxy

What's hot (20)

PDF
Memcached Study
PPTX
Apache Performance Tuning: Scaling Up
PPT
Develop with linux containers and docker
PDF
Automating complex infrastructures with Puppet
PDF
Apache Traffic Server & Lua
PPTX
Usenix LISA 2012 - Choosing a Proxy
PDF
Automating Complex Setups with Puppet
PDF
EWD 3 Training Course Part 33: Configuring QEWD to use CORS
PDF
ReplacingSquidWithATS
PDF
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
KEY
How Flipkart scales PHP
PDF
Integrated Cache on Netscaler
PDF
Speed up your Symfony2 application and build awesome features with Redis
PPTX
Caching
PPTX
KEY
Introduction to memcached
ODP
Cassandra as Memcache
PDF
Cobbler, Func and Puppet: Tools for Large Scale Environments
PDF
How To Set Up SQL Load Balancing with HAProxy - Slides
PDF
Australian OpenStack User Group August 2012: Chef for OpenStack
Memcached Study
Apache Performance Tuning: Scaling Up
Develop with linux containers and docker
Automating complex infrastructures with Puppet
Apache Traffic Server & Lua
Usenix LISA 2012 - Choosing a Proxy
Automating Complex Setups with Puppet
EWD 3 Training Course Part 33: Configuring QEWD to use CORS
ReplacingSquidWithATS
Handling 10k requests per second with Symfony and Varnish - SymfonyCon Berlin...
How Flipkart scales PHP
Integrated Cache on Netscaler
Speed up your Symfony2 application and build awesome features with Redis
Caching
Introduction to memcached
Cassandra as Memcache
Cobbler, Func and Puppet: Tools for Large Scale Environments
How To Set Up SQL Load Balancing with HAProxy - Slides
Australian OpenStack User Group August 2012: Chef for OpenStack
Ad

Similar to Varnish intro (20)

PPTX
Mini-Training: To cache or not to cache
PPTX
Pure Speed Drupal 4 Gov talk
PDF
High Performance Drupal Sites
PPT
Drupalcamp Estonia - High Performance Sites
PPT
Drupalcamp Estonia - High Performance Sites
PDF
Service-Oriented Design and Implement with Rails3
PDF
A Tale of 2 Systems
PDF
High Performance Drupal
PPTX
Drupal performance
PDF
DrupalCampLA 2014 - Drupal backend performance and scalability
PDF
DrupalSouth 2015 - Performance: Not an Afterthought
PDF
Drupal is not your Website
PDF
JavaScript Service Worker Design Patterns for Better User Experience
PDF
Michael stack -the state of apache h base
PPTX
72d5drupal
PPTX
Alfresco Tech Talk Live (Episode 70): Customizing Alfresco Share 4.2
PDF
Do you lose sleep at night?
PPT
Drupal: an Overview
PDF
Drupal Is Not Your Web Site
PDF
Velocity - Edge UG
Mini-Training: To cache or not to cache
Pure Speed Drupal 4 Gov talk
High Performance Drupal Sites
Drupalcamp Estonia - High Performance Sites
Drupalcamp Estonia - High Performance Sites
Service-Oriented Design and Implement with Rails3
A Tale of 2 Systems
High Performance Drupal
Drupal performance
DrupalCampLA 2014 - Drupal backend performance and scalability
DrupalSouth 2015 - Performance: Not an Afterthought
Drupal is not your Website
JavaScript Service Worker Design Patterns for Better User Experience
Michael stack -the state of apache h base
72d5drupal
Alfresco Tech Talk Live (Episode 70): Customizing Alfresco Share 4.2
Do you lose sleep at night?
Drupal: an Overview
Drupal Is Not Your Web Site
Velocity - Edge UG
Ad

More from Boyan Borisov (8)

PDF
DrupalCon Europe 2020 - Drupal loves NoSQL databases or how to serve 1 milli...
PPTX
Drupal Layout Builder Ecosystem
PPTX
Drupal in the cloud - Serverless and more
PPTX
Drupal in the cloud - Serverless and more
PPTX
Better editorial experience in Drupal 7
PPTX
Large Scale Drupal - Behind the Scenes
PPTX
Better editorial experience in Drupal 7
PPTX
Putting "Phings" together - how to automate your life
DrupalCon Europe 2020 - Drupal loves NoSQL databases or how to serve 1 milli...
Drupal Layout Builder Ecosystem
Drupal in the cloud - Serverless and more
Drupal in the cloud - Serverless and more
Better editorial experience in Drupal 7
Large Scale Drupal - Behind the Scenes
Better editorial experience in Drupal 7
Putting "Phings" together - how to automate your life

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Spectroscopy.pptx food analysis technology
Chapter 3 Spatial Domain Image Processing.pdf
Understanding_Digital_Forensics_Presentation.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation_ Review paper, used for researhc scholars
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
The Rise and Fall of 3GPP – Time for a Sabbatical?
Agricultural_Statistics_at_a_Glance_2022_0.pdf

Varnish intro

  • 2. About me • Boyan Borisov • Team Leader @ Propeople • boyanb@propeople.dk • @boyan_borisov • Skype: boian.borisov • http://linkedin.com/in/ boyanborisov
  • 3. What is Varnish? • Reverse proxy cache server • ... and more (load balancer, filter, director, ...) • Open Source (BSD), commercially supported • Typically in front of a LAMP stack
  • 4. Why do we need Varnish? • Believe or not Drupal is not very fast by default ;) • “Large Scale Drupal” is not only a sales phrase but the present and the future of Drupal • May be this is the best and fastest way to achieve great performance results
  • 5. Why do we need Varnish?
  • 7. What can be cached? • Drupal pages for anonymous users • Static content: images, js, css • Other types of static or generated content • Varnish stores a cache entry for each Host + URL
  • 8. What should NOT be cached in Varnish? • Responses to POST requests • Responses with a Set-Cookie : header • User-specific content (logged-in page requests) • Very large media files (> 100MB) • Has a Cache-Control: no-cache header
  • 9. When the cache will expire? • Response header: Cache-Control: max-age= 300 • If no Cache-Control specified then Varnish uses the Expires date, if specified • If no Cache-Control or Expires header then uses Varnish's default TTL which is 2 minutes but could be changed
  • 10. But wait… what about Drupal? • Install varnish • Install and configure the Drupal varnish module - https://drupal.org/project/varnish • Update the default Varnish VCL configuration with a Drupal related one – https://github.com/boyanborisov/varnish-for-drupal – https://fourkitchens.atlassian.net/wiki/display/TECH/ Configure+Varnish+3+for+Drupal+7 – https://drupal.org/node/1427486 • And don’t forget to enable the caching for the anonymous users
  • 12. VCL – Varnish Configuration Language • Extend and modify Varnish cache policies • Add behaviors during each phase of delivery • Each Request is processed separately and independently • States are isolated but are related • Return statements exit one state and start another • VCL defaults are ALWAYS appended below your own VCL
  • 13. Other VCL features • Add/remove/change HTTP headers • Redirects based on request parameters • Rewrite requests • Retry failed requests • Saint and Grace: Deliver cached content when backend is unresponsive • ACLs: Network-address filtering • Request filtering ESI: Separate cache entries and separate cache policies for each part of a document • Inline C code
  • 14. VCL – Subroutines – breaking it down • vcl_init – VCL is loaded, no request yet; VMOD initialization • vcl_recv – Beginning of request, req is in scope • vcl_pipe – Client & backend data passed unaltered • vcl_pass – Request goes to backend and not cached • vcl_hash – call hash_data to add to the hash • vcl_hit – called on request found in the cache • vcl_miss – called on request not found in the cache • vcl_fetch – called on document retrieved from backend • vcl_deliver – called prior to delivery of cached object • vcl_error – called on errors
  • 15. Directors • Directors allow you to talk to the backend servers • Directors are a glorified reverse proxy – Allows for certain types of load balancing – Allows for talking to a cluster “A director is a logical group of backend servers clustered together for redundancy. The basic role of the director is to let Varnish choose a backend server amongst several so if one is down another can be used.”
  • 16. Varnish realtime tools • varnishstat – realtime status and performance metrics • varnishhist – live frequency plot of response times • varnishtop – live list of hottest files • varnishlog – analyze incoming HTTP headers • Varnish CLI – live admin capabilities
  • 17. Drupal specifics • Drupal emits Vary – Cookie,Accept-Encoding • Cookie – Avoids cache collisions between users Accept-Encoding : maintain separate cache entries for compressed content (gzip, deflate) vs. uncompressed content
  • 18. ESI – Edge Side Includes • ESI is a small markup language much like SSI (server side includes) to include fragments (or dynamic content for that matter) • Think of it as replacing regions inside of a page as if you were using XHR (AJAX) but single threaded. • Three Statements can be utilized – esi:include – Include a page – esi:remove – Remove content – <!-- esi --> - ESI disabled, execute normally
  • 19. How to cache authenticated users? • Authcache - https://drupal.org/project/authcache “Authcache saves the final rendered HTML of a page to serve visitors. A separate cache is created for each user role as defined by the administrator, so some roles can be excluded if necessary. Authcache places priority on serving pages to the visitor as fast as possible. After a page is loaded by the browser, a second HTTP request may be performed via Ajax. This initiates a lightweight DRUPAL_BOOTSTRAP_SESSION that allows SQL queries to be executed , and returns any user-customized data to the page (such as form tokens or default values on a contact form).”
  • 20. How to cache authenticated users?
  • 21. How to cache authenticated users?
  • 22. How to cache authenticated users? “Production graphs from intranet solution developed by Propeople ( around 50 000 users ). Web CPU usage below 1% and varnish hit ratio > 80%. Varnish & Propeople rocks  ” Rumen Yordanov Open Source Department manager @Propeople
  • 23. Cache invalidation • Drupal invalidate the whole Varnish cache on node/comment/etc save by default • Expire module is a solution - https://drupal.org/project/expire
  • 24. Purging and banning • Purging – a purge is what happens when you pick out an object from the cache and discard it along with its variants. Usually a purge is invoked through HTTP with the method PURGE. • Banning – You can think of bans as a sort of a filter on objects already in the cache. You ban certain content from being served from your cache. You can ban content based on any metadata we have. A ban will only work on objects already in the cache, it does not prevent new content from entering the cache or being served.
  • 25. Demo