Varnish the Drupal way
About me Boyan Borisov Team Leader @ Propeople boyanb@propeople.dk @boyan_borisov Skype: boian.borisov hap://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 StaSc content: images, js, css Other types of stasc 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 - haps://drupal.org/project/varnish Update the default Varnish VCL configurason with a Drupal related one haps://github.com/boyanborisov/varnish- for- drupal haps://fourkitchens.atlassian.net/wiki/display/tech/ Configure+Varnish+3+for+Drupal+7 haps://drupal.org/node/1427486 And don t forget to enable the caching for the anonymous users
Varnish state machine
VCL Varnish ConfiguraSon 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
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 realsme tools varnishstat realsme status and performance metrics varnishhist live frequency plot of response Smes varnishtop live list of hoaest files varnishlog analyze incoming HTTP headers Varnish CLI live admin capabilises
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 maaer) Think of it as replacing regions inside of a page as if you were using XHR (AJAX) but single threaded. Three Statements can be uslized esi:include Include a page esi:remove Remove content <!- - esi - - > - ESI disabled, execute normally
How to cache authenscated users? Authcache - haps://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. Aser a page is loaded by the browser, a second HTTP request may be performed via Ajax. This inisates 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 authenscated users?
How to cache authenscated users? - 50 000 users - Web CPU usage below 1% - varnish hit raso > 80%. - Varnish rocks J
Cache invalidason Drupal invalidate the whole Varnish cache on node/comment/etc save by default Expire module is a soluson - haps:// drupal.org/project/expire
QuesSons?