SlideShare a Scribd company logo
1 of 91
Download to read offline
GLOBAL AGENCY : e-communication                  e-technology         e-systems




eZ Summer Camp 2012
eZ Publish Varnish Integration
How to optimize your eZ Publish with Varnish Reverse
Proxy




        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel    06/09/2012   1
Novactive
About us




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   2
Novactive
                                                                                                      PARIS OFFICE
NOVACTIVE, in a nutshell
                                                                                                   42/44 rue du Paradis
Nicolas GENTY           Bruno BASTET        Damien LHOUILLIER                                          75010 Paris
Director                VP of WW Sales      CTO                                                           France


                                                                                                   MONTREAL OFFICE
 TEAM (75 employees)                                            Key Figures                         360 rue Saint Jacques
!  Top management : 3                    !  Design : 5          !    Creation date: 1996             Ouest - Suite 1805
!  Sales : 9                                                    !    Net Worth (Dec10): $486K       Montréal, QC H2Y 1P5
!  Consulting & Projet management : 19
                                         !  Engineering and
                                                                !    Sales (2011): aprox: $5M              Canada
                                            Development : 38
                                                                !    Workforce 2012: 75
3 locations : Paris, Montréal et Tunis                                                          PARTNERSHIP & EXPERTISE
                                                                                                        Platinum eZPublish
                                                                                                        Partner

MAIN CUSTOMERS                                  WHAT WE DO?
                                                                                                        Varnish partner
                                                Consulting & Expertise: Consulting,
                                                support design and implementation for
                                                                                                         Emailvision partner
                                                Web & Mobile, Design, Online Marketing
                                                                                                       certified ISO 9001 v.
                                                Web and mobile development: Web:
                                                                                                       2008
                                                Expertise in cutting-edge Open Source                  In 2009, 2010 and 2011
                                                technologies, mobile iPhone and Android
                                                Development                                             Expertise on mobile
                                                                                                        (Web and native Apps)




                   eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel                 06/09/2012                 3
About me

Engineering and Innovation Director @Novactive

  !   Quick summary
     !   Since 2003 at Novactive
     !   Since 2005 on eZ Publish
     !   Since 2010 on iOS
     !   Since 2010 with Varnish



  ! Twitter : Plopix
  !   Blog : http://blog.plopix.net
  !   Mail : seb@novactive.com




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   4
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   5
Summary


                                                     Reminder of basics
                                                          -    Architecture
 !     Novactive                                          -    Varnish
                                                          -    VCL
 !     Reverse Proxy                                      -    Varnish Flow
 !     Varnish eZ Publish Architecture                    -    MISS / HIT definition
 !     Varnish Basics                                     -    Installation and Configuration

 !     Varnish Advanced #1
 !     ESI Basics
 !     ESI with eZ Publish
 !     Recursive ESI
 !     Varnish purge on eZ Publish publication
 !     Varnish Advanced #2




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012       6
Summary


                                                     VCL tips and tricks
                                                          -    Debug
 !     Novactive                                          -    ACL
 !     Reverse Proxy                                      -    C code
                                                          -    Implementations
 !     Varnish eZ Publish Architecture
 !     Varnish Basics
 !     Varnish Advanced #1
 !     ESI Basics
 !     ESI with eZ Publish
 !     Recursive ESI
 !     Varnish purge on eZ Publish publication
 !     Varnish Advanced #2




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   7
Summary


                                                     Edge Side Include
                                                          -    Defintion
 !     Novactive                                          -    Tips and tricks
                                                          -    ESI content view
 !     Reverse Proxy
                                                          -    Recursive usage
 !     Varnish eZ Publish Architecture                    -    Implementations
 !     Varnish Basics
 !     Varnish Advanced #1
 !     ESI Basics
 !     ESI with eZ Publish
 !     Recursive ESI
 !     Varnish purge on eZ Publish publication
 !     Varnish Advanced #2




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   8
Summary


                                                     Instant publishing
                                                         -  Tricks
 !     Novactive                                         -  Unleash the TTL
 !     Reverse Proxy                                     -  Varnish purge
                                                          -  Implementation
 !     Varnish eZ Publish Architecture
 !     Varnish Basics
 !     Varnish Advanced #1
 !     ESI Basics
 !     ESI with eZ Publish
 !     Recursive ESI
 !     Varnish purge on eZ Publish publication
 !     Varnish Advanced #2




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   9
Summary


                                                     Varnish daemon
                                                         -  Tips and Tricks
 !     Novactive                                         -  VCL advanced
 !     Reverse Proxy                                     -  Performance optimization
 !     Varnish eZ Publish Architecture                   -  Troubeshoot your instance
                                             -  Implementation
 !     Varnish Basics
 !     Varnish Advanced #1
 !     ESI Basics
 !     ESI with eZ Publish
 !     Recursive ESI
 !     Varnish purge on eZ Publish publication
 !     Varnish Advanced #2




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   10
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   11
Reverse Proxy
General




     eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   12
Reverse Proxy features

Features
  ! Handles a HTTP Cache
  ! Handles ESI (Edge Side Include)

Advantages
  ! Optimize the usage of your webserver
       !   Therefore of your database
  !    Allows us to handle high peaks of traffic


Disadvantages
  !     Works on a short TTL (Time To Live)
  !     Delaying the publication with 2xTTL time
  !     Induced time lag of contents
  !     The permanent dilemma:
       !   The greater the TTL is, the older the information could be
       !   The more you reduce the TTL, the less you handle high traffic




             eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   13
Reverse Proxy

Main Open Source Reverse Proxy in the world

  ! Squid

  !   Apache

  ! Lighthttpd

  ! Nginx

  ! Varnish




        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   14
Reverse Proxy architecture


Architecture

   !   Clients
     !   Resources who issues the request



   ! Backends
     !   The different webservers behind Varnish



   ! Backend storage
     !   The cache storage method


   !   Configuration
     !   Set of rules to manage application




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   15
Reverse Proxy architecture

Basic platform integration


                                                                            Web Server


                                     ReverseProxy                           Web Server

       Visitors
                                                                            Web Server




  !   You can see a reverse proxy as a shield of your web server
      farm.




        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel    06/09/2012   16
Reverse Proxy architecture

Generic diagram (MISS and HIT)
                      Request                             If not in the cache



                  backend response                        backend response




                      Request



                  backend response



     Visitors                             Reverse                                Backend
    Browsers                               Proxy                                 Apache
     Clients                                                                    Web server


        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel       06/09/2012   17
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   18
eZ Publish without Varnish
Classic eZ Publish Architecture




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   19
Classic architecture

                                              Visitors




                              eZ
                                                                               Contributors




                                MySQL




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012         20
eZ Publish with Varnish
Classic eZ Publish with Varnish




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   21
Classic Architecture + Varnish

                                              Visitors




                             Varnish




                              eZ
                                                                               Contributors




                                MySQL




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012         22
eZ Publish Cluster without Varnish
eZ DFS Classic eZ Publish Architecture




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   23
eZ DFS Classic architecture

                                                 Visitors




                          Load Balancer




  eZ                    eZ                       eZ                  eZ

                                                                                       Contributors


                                 eZ DFS




       NFS                                                              MySQL



        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel       06/09/2012       24
eZ Publish Cluster with Varnish
eZ DFS eZ Publish with Varnish




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   25
eZ DFS Architecture + Varnish

                                 Load Balancer



   Visitors
                     Varnish                            Varnish




  eZ                      eZ                       eZ                  eZ

                                                                                         Contributors


                                   eZ DFS




        NFS                                                               MySQL



          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel       06/09/2012       26
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   27
Varnish basics
Configuration




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   28
Varnish Basics

Installation

Configuration in service mode
   !   /etc/default/varnish
        !   Service global configuration



   !   /etc/varnish/yourconfiguration.vcl
        !   All your rules to handle HTTP cache in your application




Global configuration
   !     Socket port and socket admin port
   !     Memory
   !     Process limitation
   !     Default TTL
   !     VCL file path


            eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   29
Varnish Basics

VCL : Varnish Configuratin Language
   ! Syntax from C and Perl
   !   No loops, no variables
=> It describes the caching policy !

Syntax
   !   # and /* foo */ for comments
   !   sub $name functions

Functions
   !     regsub(str, regex, sub) / regsuball(str, regex, sub)
   !     ban_hash(regex) / ban_url(regex) / ban (expression)
   !     restart
   !     return()

Based on a Request Flow


           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   30
Simplified Varnish request flow




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   31
Varnish flow in diagram

Macro Simplified Varnish Flow : MISS
                   Request
                                                vcl_recv

                                               vcl_hash

                                                 Is this request in
                                                    my cache ?

                                                           Request                      page
                                                                                      generation

                                               vcl_fetch

                                               vcl_deliver

               backend response
   Visitors                            Varnish                               Backend
   Browser                                                                   Apache
   Clients                                                                  Web server


        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel    06/09/2012       32
Varnish flow in diagram

Macro Simplified Varnish Flow : HIT


                   Request
                                                vcl_recv

                                               vcl_hash

                                                 Is this request in
                                                    my cache ?

                                               vcl_deliver

               backend response




   Visitors                            Varnish                               Backend
  Browsers                                                                   Apache
   Clients                                                                  Web server


        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel    06/09/2012   33
Varnish Flow

Recv
   ! Called at the beginning of a request, after the complete request
     has been received

Fetch
   ! Called when the requested object has been retrieved from the
     backend

Deliver
   ! Called before a cached object is delivered to the client

Hash
   ! Called to define the unicity of a cached object

Error
   ! Called when an error occurs



          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   34
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   35
Varnish advanced #1
VCL: Varnish Configuration Language




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   36
Varnish advanced #1

Debug information
  !   Usually added in the headers
  !   But, in the response headers !

HIT or MISS ?
  !   Most important information
  !   In the vcl_deliver
             # Called before a cached object is delivered to the client !
             sub vcl_deliver {!
                 if (obj.hits > 0) {!
                     set resp.http.X-Cache = "HIT”;!
                     set resp.http.X-Cache-Hits = obj.hits;!
                 } else {!
                     set resp.http.X-Cache = "MISS";!
                 }!
                 set resp.http.WhoisCache = "eZ Summer Camp Conf – Varnish 1”!
                 return(deliver);!
             }!




  !   You should also add
    !   the “hits” counter
    !   the name of the Varnish server ( if you are in a multi server architecture)



         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel       06/09/2012   37
Varnish advanced #1

MISS ? Why ?

  !   Different ways to have a MISS
    !   It’s the first call after an expiration
    !   Because it’s a rule in the vcl_recv
       !   return(pass)
    !   Because it’s a rule in the vcl_fetch
       !   return(hit_for_pass)



  !   How to find out why you have a MISS
    !   In the recv
       !   Only access to the request (req)
    !   In the fetch
       !   You have access to the response (beresp)


  !   Solution ?
    !   Add Header into the request in the recv function
    !   Copy these headers into the response in the fetch function




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   38
Varnish advanced #1

MISS ? Why ?
  !   In the vcl_recv

             # called at the beginning of a request, after the complete request has been received!
             sub vcl_recv {!
             !
             … some rules …!
             !
             if (req.request == "POST") {!
                 set req.http.X-Debug = "Not Cached according to configuration (POST)"; }!
                 return(pass);!
             }   !




  !   In the vcl_fetch
         # Called when the requested object has been retrieved from the backend!
         sub vcl_fetch {!
         !
         … some rules …!
         !
         # show our debug       "!
         set beresp.http.X-Debug-recv = req.http.X-Debug;!
         !
         … some rules …!
         !
         # You are respecting the Cache-Control=private header from the backend!
         if ( beresp.http.Cache-Control ~ "private") {!
             set beresp.http.X-Debug-fetch = "Not Cached according to configuration (Cache-Control)”;!
             set beresp.ttl = 0s;!
             return(hit_for_pass);!
         }!
         !




             eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel           06/09/2012      39
Varnish advanced #1


Add ACL
  !   Everybody can see these headers
  !   Not very secure
              # ACL for debug IP!
              acl debuggers {!
                  "localhost";!
                  "192.168.0.0"/16;!
              }!
              !




  !   Usage

              # pass mode can't handle POST (yet) so use pipe!
              if (req.request == "POST") {!
                   if (client.ip ~ debuggers) {!
                       set req.http.X-Debug = "Not Cached according to configuration (POST)”;!
                       return(pass);!
                   }!
              }   !




        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel            06/09/2012   40
Varnish advanced #1


Add C in your VCL
  !   Useful to do very specific stuff

           C{!
                    You C code!
           }C   !




  !   You have to see into the source code of Varnish to know the valid
  method

           if( beresp.http.X-ttl ~ "s$"){ # seconds!
               C{!
                    char *ttl;!
                    ttl = VRT_GetHdr(sp, HDR_BERESP, "06X-ttl:");!
                    VRT_l_beresp_ttl(sp, atoi(ttl));!
               }C!
           }!




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   41
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   42
Edge Side Include
Definition




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   43
Edge Side Include


Definition

   ! markup language
     !   not interpreted by the web server


                                                          !
             <esi:include src="http://example.com/1.html"/>




   !   Inclusion of pages fragments
   !   Assembled on the edges
     !   On reverse proxy (Varnish, Akamai, or other CDNs)


   !   Enable ESI in the VCL fetch method

       set beresp.do_esi = true;   !




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   44
Edge Side Include


Be careful

   !   Do not parse ESI in images and binary content

   !   Self-closing XML element

   !   ESI will be ignored in pipe (see Varnish Flow)

   !   ESI requests are considered as isolated requests
     !   Don’t forget that !




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   45
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   46
ESI with eZ Publish
A cache-block replacement




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   47
ESI with eZ Publish


Objectives

  !   Managing cache-block

  !   Varnish became an applicative part of the platform

  !   ESI System
    !   Deleting cache-block and using benefit of ESI views


  !   Update these caches (old cache -block) with the ezpublish view
  caching system.



  !   Let’s introduce the ESI content view...




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   48
ESI with eZ Publish

Standard pagelayout : With cache-block
   Pagelayout

    Header (cache-block)

    Menu                                                                      Sidebar
    (cache-block)                                                             (cache-block)




                                                View




    Footer (cache-block)


        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012        49
ESI with eZ Publish

ESI pagelayout: Without cache-block
   Pagelayout

    Header (/content/view/header/2)

    Menu                                                                        Sidebar
    (/content/view/menu/N)                                                      (/content/view/sidebar/
                                                                                N)




                                                  View




    Footer (/content/view/footer/2)


          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012            50
ESI with eZ Publish


Cache-block reminder performance and usage

  !   ignore_content_expiry
    !   WITHOUT : each publication expires all your cache-block
    !   WITH : you have to wait the TTL (expiry)


  !   subtree_expire
    !   Not very useful in most case
    !   Needs cronjob


  !   keys
    !   two templates with same keys will generate at least 2 cache-block



  !   In general, cache-block can be a performance killer !




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   51
ESI with eZ Publish


ESI content view

  !   Forget the key concept of the cache-block

  !   Think about
    !   content view
    !   view cache system
    !   smart view cache system


  !   For now, each ESI content view will have short TTL
    !   But keep in mind, that it won’t always be the case




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   52
ESI with eZ Publish


ESI content view                 VS          cache-block


   !   When the TTL is expired, there is no generation
       !   You get the view cache


   !   You can easily clear a view
       !   For now you have to wait the Varnish TTL


   !   You can use these views everywhere
       !   In another view, or in the pagelayout !



   !   And if you want a TTL regeneration, don’t add the view in your
       CacheViewModes




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   53
How to do better ?




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   54
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI with eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   55
Recursive ESI with eZ Publish
Simplify your code




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   56
Recursive ESI with eZ Publish


Concept

   ! Varnish supports recursive ESI inclusion

   !   Limited by the max_esi_includes parameter

   ! Very useful when you have to browse a tree

   ! It’s the one way to use ESI content view




        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   57
Can we do better ? Again?
Yes !




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   58
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI for eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   59
Varnish purge on eZ Publish
publication
Unleash your TTL




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   60
Varnish purge on publication


Concept

   ! When eZ Publish expires a content view, forward this expiration to
     Varnish

   !   How ? 2 ways to send a purge request
     !   Use the ezpEvent « content/cache »
     !   Use a StaticCacheHandler


   !   Configure the vcl to handle this request and expire the cache
       object.

   !   Use the Smart View Cache to connect the different ESI view purge

   ! After that, you can increase your TTL !
     !   To an unllimited value



         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   61
Varnish purge on publication


First, how to handle a purge request
   !   In the vcl_recv




    if (req.request == "BAN") {!
        # ACL check and quick return (error)!
        if (!client.ip ~ purgers) {!
            error 405 "Method not allowed";!
        }!
               "           "!
        if (req.url ~ "^/url/") {!
            ban_url(regsub(req.url, "^/url/", ""));!
            error 200 "Purge of objects with url ("+regsub(req.url, "^/url/", "")+") done.";!
        }!
    }!




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel           06/09/2012   62
!     Novactive
!     Reverse Proxy
!     Varnish eZ Publish Architecture
!     Varnish Basics
!     Varnish Advanced #1                                         Summary
!     ESI Basics
!     ESI for eZ Publish
!     Recursive ESI
!     Varnish purge on eZ Publish publication
!     Varnish Advanced #2




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   63
Varnish advanced #2
VCL advanced




     eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   64
Varnish advanced #2

Pool of backend
    !   random
              director www_director random {!
                  {!
                       .backend = web1;!
                       .weight = 1;!
                  }      "!
                  {!
                        .backend = web2;!
                        .weight = 1;!
                  }!
              }!
              !




    !   Don’t forget to add the second backend

              backend web2 {!
                         ".host = "localhost";!
                         ".port = "80";!
              }   !




    !   Change the backend

              set req.backend = www_director;
!                                               !




     !



          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   65
Varnish advanced #2


Check the heath of your backend

  !   Poke your backend every N seconds
  !   Affects backend selection
            backend web1 {!
                .host = "localhost";!
                .port = "80";!
                .probe = {!
                    .url = "/";!
                    .interval = 3s;!
                    .window = 5;!
                    .threshold = 2;!
                }!
            }!




  !   Varnish doesn’t send Host with health checks.
            .probe = { !
                .request =!
                     "GET / HTTP/1.1"!
                     "Host: www.foo.bar"!
                     "Connection: close";
                                        !




  !   Don’t set the eZ Publish home page for the probe.


        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   66
Varnish advanced #2


Check the heath of your backend

  !   req.grace (in the vcl_recv)
    !   accept serving 30 minutes old object
               # set the grace!
               set req.grace = 30m;
                                  !




  !   beresp.grace (in the vcl_fetch)
    !   keep all objects for 30 minutes beyond their TTL


               # set the grace!
               Set beresp.grace = 30m;!




  !   It’s like the “Stale cache”




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   67
Varnish advanced #2



RewriteRule
  !   Varnish can do it

          sub vcl_recv {!
          !
          … some rules …!
          !
                  if ( req.url ~ "^/layout/(.[^/]*)/([0-9]*)(.*)$" ) {!
                     set req.url = regsub( !
                         "           "           "req.url, !
                         "           "           ""^/layout/(.[^/]*)/([0-9]*)(.*)$", !
                         "           "           ""/layout/set/1/content/view/full/23”!
                         "           ");!
                  }!
          !
          … some rules …!
          !
          }   !




        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel              06/09/2012   68
Varnish advanced #2


Do a 301 HTTP redirection

         sub vcl_recv {!
         !
         … some rules …!
         !
         if (req.http.host ~ "agreatbutlongdns.ezsc" ) {!
             error 301 "ezpublish4.ezsc"; #see vcl_error!
         }!
         … some rules …!
         !
         }!
         !
         sub vcl_error {!
              … some rules …!
              if (obj.status == 301) {!
                  set obj.http.Location = "http://" + obj.response + ":" + server.port + req.url;!
               } else {!
                   … some rules …!
               }!
         }!
         !
         !




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel            06/09/2012       69
Varnish advanced #2
Usage




        eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   70
Varnish advanced #2


varnishlog




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   71
Varnish advanced #2


varnishlog

  !   quite extensive

  !   filter information you need

  !   Useful to debug what happens
    !   And valid your configuration


Best options
    !   –o : group by request
    !   -b : only show traffic related to a backend
    !   -c : only show traffic related to a client
    !   -i <tag> : only show one tag




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   72
Varnish advanced #2


varnishtop

  !   Useful to know some real-time information

    !   top URLs sent to the client

    !   top URLs sent to the backend




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   73
Varnish advanced #2


varnishncsa

  !   It allows you to log client access as Apache do

  !   NCSA log file example




    127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/Getting-Started/Selected-
    Features HTTP/1.1" 200 4314 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"!
    127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/content/view/tagcloud/2
    HTTP/1.1" 200 3371 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"!
    127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/content/view/sitemap/2
    HTTP/1.1" 200 3187 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"!
    127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/content/advancedsearch
    HTTP/1.1" 200 4505 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"}!
    !
    !




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel          06/09/2012             74
Varnish advanced #2


varnishstat

  !   Perfect tool to get a good representation of your Varnish health

  !   Some useful statistic
    !     Uptime
    !     HIT rate
    !     Client connections accepted
    !     Client connections received
    !     Cache HIT
    !     Cache MISS
    !     Failed backend connections




            eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   75
Varnish advanced #2


varnishstat




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   76
Varnish advanced #2



  !       Find the URL the most sent to the backend

      Varnistop –i TxURL!
      !
      !




  !       Find the URL the most asked by the client

      Varnistop –i TxURL!
      !
      !




  !   Have you try the « -j » option of varnishstats
          !   new in 3.03 since 08/20/12




              eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   77
Varnish advanced #2
Daemon configuration




      eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   78
Varnish advanced #2


BAN Console
  !   Access
    !   varnishadm
    !   telnet localhost 6082


  !   Tunable paramaters
    !   param.show –l



  !   Be careful about the thread parameters
    ! 
     root@ezsc ~ # varnishadm param.show | grep thread!
     cc_command                  "exec gcc -std=gnu99 -g -O2 -pthread -fpic -shared -Wl,-x -o %o %s"!
     thread_pool_add_delay       2 [milliseconds]!
     thread_pool_add_threshold   2 [requests]!
     thread_pool_fail_delay      200 [milliseconds]!
     thread_pool_max             2000 [threads]!
     thread_pool_min             1 [threads]!
     thread_pool_purge_delay     1000 [milliseconds]!
     thread_pool_stack           65536 [bytes]!
     thread_pool_timeout         120 [seconds]!
     thread_pool_workspace       16384 [bytes]!
     thread_pools                2 [pools]!
     thread_stats_rate           10 [requests]!




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel          06/09/2012         79
Varnish advanced #2


Threading parameters
  !   Number of threads
    !   how many requests Varnish can serve concurrently


  !   Minimum threads running = thread_pools * thread_pool_min
    !  2 * 1 = 2
  !   Maximum threads running = thread_pool_max
    !   2000



  !   Don’t forget to add your configuration in the default configuration
    !   /etc/default/varnish




          eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   80
Varnish advanced #2


Real-time configuration changes

  !   you can change a param with varnishadm
    !   but don’t forget to add the new parameter value in the daemon file configuration


  !   About the VCL, be careful because a restart empties the cache
    !   Varnish don’t keep cache
    !   very bad idea in a production environment !


  !   So let’s use varnishadm in order to reload the VCL




         eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012    81
To sum up…




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   82
To sum up


On the network administration side, you know

  !   How to set architecture of your plateform

  !   How to configure your Varnish

  !   How to optimize the daemon

  !   How to optimize your VCL

  !   How to troubleshoot your instance




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   83
To sum up


On the developer side, you know


  !   How to make a good conception with ESI content view

  !   How to remove cache-block and unleash your instance

  !   How to purge cache on publication




       eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   84
Conclusion




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   85
Conclusion


Achieved objectives
   !   You can now have a production website with
       !   98% of requests cached by Varnish
       !   2 % of traffic handle by your webserver farm


   !   Set a architecture with
       !   A database dedicated to the backoffice and to the generation on new content
       !   A very low usage of your NFS



   !   Beyond speed, more security
       !   Your website is all the time available due to the shield protection of Varnish
       !   even if we have server problems




            eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   86
eZ Accelerator

To go further, discover eZ Accelerator available on the eZ Market




Key Features
   !   Full support of URLs
       !   URL Translator, Siteaccess, PathPrefix, StaleCache etc..
   ! Asynchronous purge
   !   Multi varnish architecture
   !   Cache purge on content publication
   !   Dedicated interface to manage your Varnish servers

           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   87
What about eZ Publish 5


eZ Publish 5 with Varnish
   !   Varnish on Symfony 2
       ! Totally integrated with the HTTP Cache system
       !   ESI are directly handled by the template and cache system


   !   Two caching models
       !   Expiration model
          ! Based on the TTL
       !   Validation model
          ! Based on eTag


   !   Always the same rule : Never generate the same response twice !


   !   So all the concept seen on this workshop are relevant with eZ Publish 5




           eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   88
Questions ?




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   89
Thank you!




    eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   90
Adresse : 42-44, rue de Paradis
          75010 PARIS

Téléphone : 01.48.24.33.60
Fax : 01.48.24.33.54

Email : info@novactive.com
Site : www.novactive.com

SARL au capital de 132.576 euros
RCS Paris B 408 999 233




               eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel   06/09/2012   91

More Related Content

Similar to Optimize your eZ Publish with Varnish

EvokedSet PR and Web working together
EvokedSet PR and Web working togetherEvokedSet PR and Web working together
EvokedSet PR and Web working togetherlpople
 
EvokedSet company presentation
EvokedSet company presentationEvokedSet company presentation
EvokedSet company presentationnickyldavis
 
Is your store ‘social media’ ready ? - MORE Vision by MAPIC
Is your store ‘social media’ ready ? - MORE Vision by MAPIC Is your store ‘social media’ ready ? - MORE Vision by MAPIC
Is your store ‘social media’ ready ? - MORE Vision by MAPIC MIPIMWorld
 
What is AZNetwork ? (english version)
What is AZNetwork ? (english version)What is AZNetwork ? (english version)
What is AZNetwork ? (english version)AZNetwork
 
Customer Experience in a Digital & Complex World
Customer Experience in a Digital & Complex WorldCustomer Experience in a Digital & Complex World
Customer Experience in a Digital & Complex WorldRelax In The Air
 
Presentation inZair-Slideshare
Presentation inZair-SlidesharePresentation inZair-Slideshare
Presentation inZair-SlideshareinZair
 
Grow your startup with on deman talent by hayley conick at guru program sprin...
Grow your startup with on deman talent by hayley conick at guru program sprin...Grow your startup with on deman talent by hayley conick at guru program sprin...
Grow your startup with on deman talent by hayley conick at guru program sprin...TechMeetups
 
Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...
Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...
Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...Codemotion
 
What's up for 2012 and 'Commun-engineering'
What's up for 2012 and 'Commun-engineering'What's up for 2012 and 'Commun-engineering'
What's up for 2012 and 'Commun-engineering'Nicolas Pastorino
 
Building Killer Communities And Taking Confluence Social
Building Killer Communities And Taking Confluence SocialBuilding Killer Communities And Taking Confluence Social
Building Killer Communities And Taking Confluence SocialAtlassian
 
Trends in the software industry
Trends in the software industryTrends in the software industry
Trends in the software industryLi SUN
 
ITS-ON-MOBILE, Corporate presentation and references
ITS-ON-MOBILE, Corporate presentation and referencesITS-ON-MOBILE, Corporate presentation and references
ITS-ON-MOBILE, Corporate presentation and referencesDatafield
 
Ozone profile general presentation 1
Ozone profile general presentation 1Ozone profile general presentation 1
Ozone profile general presentation 1Natalliamaroz
 
Decided To Mobilise? How to Engage with the Mobile Internet User.
Decided To Mobilise? How to Engage with the Mobile Internet User.Decided To Mobilise? How to Engage with the Mobile Internet User.
Decided To Mobilise? How to Engage with the Mobile Internet User.Paul Golding
 
Creating a corporate intranet portal and enable the evolution of the digital ...
Creating a corporate intranet portal and enable the evolution of the digital ...Creating a corporate intranet portal and enable the evolution of the digital ...
Creating a corporate intranet portal and enable the evolution of the digital ...Thomas Maeder
 
Oop2012 mobile workshops
Oop2012 mobile workshopsOop2012 mobile workshops
Oop2012 mobile workshopsMichael Chaize
 

Similar to Optimize your eZ Publish with Varnish (20)

Sce Partners Overview
Sce Partners OverviewSce Partners Overview
Sce Partners Overview
 
EvokedSet PR and Web working together
EvokedSet PR and Web working togetherEvokedSet PR and Web working together
EvokedSet PR and Web working together
 
EvokedSet company presentation
EvokedSet company presentationEvokedSet company presentation
EvokedSet company presentation
 
Amaze Futures Sessions
Amaze Futures SessionsAmaze Futures Sessions
Amaze Futures Sessions
 
Is your store ‘social media’ ready ? - MORE Vision by MAPIC
Is your store ‘social media’ ready ? - MORE Vision by MAPIC Is your store ‘social media’ ready ? - MORE Vision by MAPIC
Is your store ‘social media’ ready ? - MORE Vision by MAPIC
 
What is AZNetwork ? (english version)
What is AZNetwork ? (english version)What is AZNetwork ? (english version)
What is AZNetwork ? (english version)
 
Customer Experience in a Digital & Complex World
Customer Experience in a Digital & Complex WorldCustomer Experience in a Digital & Complex World
Customer Experience in a Digital & Complex World
 
Presentation inZair-Slideshare
Presentation inZair-SlidesharePresentation inZair-Slideshare
Presentation inZair-Slideshare
 
Grow your startup with on deman talent by hayley conick at guru program sprin...
Grow your startup with on deman talent by hayley conick at guru program sprin...Grow your startup with on deman talent by hayley conick at guru program sprin...
Grow your startup with on deman talent by hayley conick at guru program sprin...
 
Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...
Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...
Matteo Santagata - Is your project scaling right? The BEE case study - Codemo...
 
The Future of ECM
The Future of ECMThe Future of ECM
The Future of ECM
 
OSS Community management
OSS Community managementOSS Community management
OSS Community management
 
What's up for 2012 and 'Commun-engineering'
What's up for 2012 and 'Commun-engineering'What's up for 2012 and 'Commun-engineering'
What's up for 2012 and 'Commun-engineering'
 
Building Killer Communities And Taking Confluence Social
Building Killer Communities And Taking Confluence SocialBuilding Killer Communities And Taking Confluence Social
Building Killer Communities And Taking Confluence Social
 
Trends in the software industry
Trends in the software industryTrends in the software industry
Trends in the software industry
 
ITS-ON-MOBILE, Corporate presentation and references
ITS-ON-MOBILE, Corporate presentation and referencesITS-ON-MOBILE, Corporate presentation and references
ITS-ON-MOBILE, Corporate presentation and references
 
Ozone profile general presentation 1
Ozone profile general presentation 1Ozone profile general presentation 1
Ozone profile general presentation 1
 
Decided To Mobilise? How to Engage with the Mobile Internet User.
Decided To Mobilise? How to Engage with the Mobile Internet User.Decided To Mobilise? How to Engage with the Mobile Internet User.
Decided To Mobilise? How to Engage with the Mobile Internet User.
 
Creating a corporate intranet portal and enable the evolution of the digital ...
Creating a corporate intranet portal and enable the evolution of the digital ...Creating a corporate intranet portal and enable the evolution of the digital ...
Creating a corporate intranet portal and enable the evolution of the digital ...
 
Oop2012 mobile workshops
Oop2012 mobile workshopsOop2012 mobile workshops
Oop2012 mobile workshops
 

Recently uploaded

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Recently uploaded (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
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
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
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
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Optimize your eZ Publish with Varnish

  • 1. GLOBAL AGENCY : e-communication e-technology e-systems eZ Summer Camp 2012 eZ Publish Varnish Integration How to optimize your eZ Publish with Varnish Reverse Proxy eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 1
  • 2. Novactive About us eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 2
  • 3. Novactive PARIS OFFICE NOVACTIVE, in a nutshell 42/44 rue du Paradis Nicolas GENTY Bruno BASTET Damien LHOUILLIER 75010 Paris Director VP of WW Sales CTO France MONTREAL OFFICE TEAM (75 employees) Key Figures 360 rue Saint Jacques !  Top management : 3 !  Design : 5 !  Creation date: 1996 Ouest - Suite 1805 !  Sales : 9 !  Net Worth (Dec10): $486K Montréal, QC H2Y 1P5 !  Consulting & Projet management : 19 !  Engineering and !  Sales (2011): aprox: $5M Canada Development : 38 !  Workforce 2012: 75 3 locations : Paris, Montréal et Tunis PARTNERSHIP & EXPERTISE Platinum eZPublish Partner MAIN CUSTOMERS WHAT WE DO? Varnish partner Consulting & Expertise: Consulting, support design and implementation for Emailvision partner Web & Mobile, Design, Online Marketing certified ISO 9001 v. Web and mobile development: Web: 2008 Expertise in cutting-edge Open Source In 2009, 2010 and 2011 technologies, mobile iPhone and Android Development Expertise on mobile (Web and native Apps) eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 3
  • 4. About me Engineering and Innovation Director @Novactive !   Quick summary ! Since 2003 at Novactive ! Since 2005 on eZ Publish ! Since 2010 on iOS ! Since 2010 with Varnish ! Twitter : Plopix !   Blog : http://blog.plopix.net !   Mail : seb@novactive.com eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 4
  • 5. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 5
  • 6. Summary Reminder of basics -  Architecture !   Novactive -  Varnish -  VCL !   Reverse Proxy -  Varnish Flow ! Varnish eZ Publish Architecture -  MISS / HIT definition ! Varnish Basics -  Installation and Configuration ! Varnish Advanced #1 !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 6
  • 7. Summary VCL tips and tricks -  Debug !   Novactive -  ACL !   Reverse Proxy -  C code -  Implementations ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 7
  • 8. Summary Edge Side Include -  Defintion !   Novactive -  Tips and tricks -  ESI content view !   Reverse Proxy -  Recursive usage ! Varnish eZ Publish Architecture -  Implementations ! Varnish Basics ! Varnish Advanced #1 !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 8
  • 9. Summary Instant publishing -  Tricks !   Novactive -  Unleash the TTL !   Reverse Proxy -  Varnish purge -  Implementation ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 9
  • 10. Summary Varnish daemon -  Tips and Tricks !   Novactive -  VCL advanced !   Reverse Proxy -  Performance optimization ! Varnish eZ Publish Architecture -  Troubeshoot your instance -  Implementation ! Varnish Basics ! Varnish Advanced #1 !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 10
  • 11. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 11
  • 12. Reverse Proxy General eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 12
  • 13. Reverse Proxy features Features ! Handles a HTTP Cache ! Handles ESI (Edge Side Include) Advantages ! Optimize the usage of your webserver ! Therefore of your database ! Allows us to handle high peaks of traffic Disadvantages !   Works on a short TTL (Time To Live) ! Delaying the publication with 2xTTL time ! Induced time lag of contents !   The permanent dilemma: !   The greater the TTL is, the older the information could be !   The more you reduce the TTL, the less you handle high traffic eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 13
  • 14. Reverse Proxy Main Open Source Reverse Proxy in the world ! Squid !   Apache ! Lighthttpd ! Nginx ! Varnish eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 14
  • 15. Reverse Proxy architecture Architecture !   Clients ! Resources who issues the request ! Backends !   The different webservers behind Varnish ! Backend storage !   The cache storage method !   Configuration !   Set of rules to manage application eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 15
  • 16. Reverse Proxy architecture Basic platform integration Web Server ReverseProxy Web Server Visitors Web Server !   You can see a reverse proxy as a shield of your web server farm. eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 16
  • 17. Reverse Proxy architecture Generic diagram (MISS and HIT) Request If not in the cache backend response backend response Request backend response Visitors Reverse Backend Browsers Proxy Apache Clients Web server eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 17
  • 18. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 18
  • 19. eZ Publish without Varnish Classic eZ Publish Architecture eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 19
  • 20. Classic architecture Visitors eZ Contributors MySQL eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 20
  • 21. eZ Publish with Varnish Classic eZ Publish with Varnish eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 21
  • 22. Classic Architecture + Varnish Visitors Varnish eZ Contributors MySQL eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 22
  • 23. eZ Publish Cluster without Varnish eZ DFS Classic eZ Publish Architecture eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 23
  • 24. eZ DFS Classic architecture Visitors Load Balancer eZ eZ eZ eZ Contributors eZ DFS NFS MySQL eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 24
  • 25. eZ Publish Cluster with Varnish eZ DFS eZ Publish with Varnish eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 25
  • 26. eZ DFS Architecture + Varnish Load Balancer Visitors Varnish Varnish eZ eZ eZ eZ Contributors eZ DFS NFS MySQL eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 26
  • 27. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 27
  • 28. Varnish basics Configuration eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 28
  • 29. Varnish Basics Installation Configuration in service mode !   /etc/default/varnish !   Service global configuration !   /etc/varnish/yourconfiguration.vcl !   All your rules to handle HTTP cache in your application Global configuration !   Socket port and socket admin port !   Memory ! Process limitation !   Default TTL ! VCL file path eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 29
  • 30. Varnish Basics VCL : Varnish Configuratin Language ! Syntax from C and Perl !   No loops, no variables => It describes the caching policy ! Syntax !   # and /* foo */ for comments !   sub $name functions Functions ! regsub(str, regex, sub) / regsuball(str, regex, sub) ! ban_hash(regex) / ban_url(regex) / ban (expression) !   restart !   return() Based on a Request Flow eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 30
  • 31. Simplified Varnish request flow eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 31
  • 32. Varnish flow in diagram Macro Simplified Varnish Flow : MISS Request vcl_recv vcl_hash Is this request in my cache ? Request page generation vcl_fetch vcl_deliver backend response Visitors Varnish Backend Browser Apache Clients Web server eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 32
  • 33. Varnish flow in diagram Macro Simplified Varnish Flow : HIT Request vcl_recv vcl_hash Is this request in my cache ? vcl_deliver backend response Visitors Varnish Backend Browsers Apache Clients Web server eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 33
  • 34. Varnish Flow Recv ! Called at the beginning of a request, after the complete request has been received Fetch ! Called when the requested object has been retrieved from the backend Deliver ! Called before a cached object is delivered to the client Hash ! Called to define the unicity of a cached object Error ! Called when an error occurs eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 34
  • 35. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 35
  • 36. Varnish advanced #1 VCL: Varnish Configuration Language eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 36
  • 37. Varnish advanced #1 Debug information !   Usually added in the headers !   But, in the response headers ! HIT or MISS ? !   Most important information !   In the vcl_deliver # Called before a cached object is delivered to the client ! sub vcl_deliver {! if (obj.hits > 0) {! set resp.http.X-Cache = "HIT”;! set resp.http.X-Cache-Hits = obj.hits;! } else {! set resp.http.X-Cache = "MISS";! }! set resp.http.WhoisCache = "eZ Summer Camp Conf – Varnish 1”! return(deliver);! }! !   You should also add !   the “hits” counter !   the name of the Varnish server ( if you are in a multi server architecture) eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 37
  • 38. Varnish advanced #1 MISS ? Why ? !   Different ways to have a MISS !   It’s the first call after an expiration !   Because it’s a rule in the vcl_recv !   return(pass) !   Because it’s a rule in the vcl_fetch !   return(hit_for_pass) !   How to find out why you have a MISS !   In the recv !   Only access to the request (req) !   In the fetch !   You have access to the response (beresp) !   Solution ? !   Add Header into the request in the recv function !   Copy these headers into the response in the fetch function eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 38
  • 39. Varnish advanced #1 MISS ? Why ? !   In the vcl_recv # called at the beginning of a request, after the complete request has been received! sub vcl_recv {! ! … some rules …! ! if (req.request == "POST") {! set req.http.X-Debug = "Not Cached according to configuration (POST)"; }! return(pass);! } ! !   In the vcl_fetch # Called when the requested object has been retrieved from the backend! sub vcl_fetch {! ! … some rules …! ! # show our debug "! set beresp.http.X-Debug-recv = req.http.X-Debug;! ! … some rules …! ! # You are respecting the Cache-Control=private header from the backend! if ( beresp.http.Cache-Control ~ "private") {! set beresp.http.X-Debug-fetch = "Not Cached according to configuration (Cache-Control)”;! set beresp.ttl = 0s;! return(hit_for_pass);! }! ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 39
  • 40. Varnish advanced #1 Add ACL !   Everybody can see these headers !   Not very secure # ACL for debug IP! acl debuggers {! "localhost";! "192.168.0.0"/16;! }! ! !   Usage # pass mode can't handle POST (yet) so use pipe! if (req.request == "POST") {! if (client.ip ~ debuggers) {! set req.http.X-Debug = "Not Cached according to configuration (POST)”;! return(pass);! }! } ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 40
  • 41. Varnish advanced #1 Add C in your VCL !   Useful to do very specific stuff C{! You C code! }C ! !   You have to see into the source code of Varnish to know the valid method if( beresp.http.X-ttl ~ "s$"){ # seconds! C{! char *ttl;! ttl = VRT_GetHdr(sp, HDR_BERESP, "06X-ttl:");! VRT_l_beresp_ttl(sp, atoi(ttl));! }C! }! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 41
  • 42. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 42
  • 43. Edge Side Include Definition eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 43
  • 44. Edge Side Include Definition ! markup language !   not interpreted by the web server ! <esi:include src="http://example.com/1.html"/> !   Inclusion of pages fragments !   Assembled on the edges !   On reverse proxy (Varnish, Akamai, or other CDNs) !   Enable ESI in the VCL fetch method set beresp.do_esi = true; ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 44
  • 45. Edge Side Include Be careful !   Do not parse ESI in images and binary content !   Self-closing XML element !   ESI will be ignored in pipe (see Varnish Flow) !   ESI requests are considered as isolated requests !   Don’t forget that ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 45
  • 46. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 46
  • 47. ESI with eZ Publish A cache-block replacement eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 47
  • 48. ESI with eZ Publish Objectives !   Managing cache-block !   Varnish became an applicative part of the platform !   ESI System !   Deleting cache-block and using benefit of ESI views !   Update these caches (old cache -block) with the ezpublish view caching system. !   Let’s introduce the ESI content view... eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 48
  • 49. ESI with eZ Publish Standard pagelayout : With cache-block Pagelayout Header (cache-block) Menu Sidebar (cache-block) (cache-block) View Footer (cache-block) eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 49
  • 50. ESI with eZ Publish ESI pagelayout: Without cache-block Pagelayout Header (/content/view/header/2) Menu Sidebar (/content/view/menu/N) (/content/view/sidebar/ N) View Footer (/content/view/footer/2) eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 50
  • 51. ESI with eZ Publish Cache-block reminder performance and usage !   ignore_content_expiry !   WITHOUT : each publication expires all your cache-block !   WITH : you have to wait the TTL (expiry) !   subtree_expire !   Not very useful in most case !   Needs cronjob !   keys !   two templates with same keys will generate at least 2 cache-block !   In general, cache-block can be a performance killer ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 51
  • 52. ESI with eZ Publish ESI content view !   Forget the key concept of the cache-block !   Think about !   content view !   view cache system !   smart view cache system !   For now, each ESI content view will have short TTL !   But keep in mind, that it won’t always be the case eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 52
  • 53. ESI with eZ Publish ESI content view VS cache-block ! When the TTL is expired, there is no generation !   You get the view cache !   You can easily clear a view !   For now you have to wait the Varnish TTL !   You can use these views everywhere !   In another view, or in the pagelayout ! !   And if you want a TTL regeneration, don’t add the view in your CacheViewModes eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 53
  • 54. How to do better ? eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 54
  • 55. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI with eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 55
  • 56. Recursive ESI with eZ Publish Simplify your code eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 56
  • 57. Recursive ESI with eZ Publish Concept ! Varnish supports recursive ESI inclusion !   Limited by the max_esi_includes parameter ! Very useful when you have to browse a tree ! It’s the one way to use ESI content view eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 57
  • 58. Can we do better ? Again? Yes ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 58
  • 59. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI for eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 59
  • 60. Varnish purge on eZ Publish publication Unleash your TTL eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 60
  • 61. Varnish purge on publication Concept ! When eZ Publish expires a content view, forward this expiration to Varnish !   How ? 2 ways to send a purge request !   Use the ezpEvent « content/cache » !   Use a StaticCacheHandler !   Configure the vcl to handle this request and expire the cache object. !   Use the Smart View Cache to connect the different ESI view purge ! After that, you can increase your TTL ! !   To an unllimited value eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 61
  • 62. Varnish purge on publication First, how to handle a purge request !   In the vcl_recv if (req.request == "BAN") {! # ACL check and quick return (error)! if (!client.ip ~ purgers) {! error 405 "Method not allowed";! }! " "! if (req.url ~ "^/url/") {! ban_url(regsub(req.url, "^/url/", ""));! error 200 "Purge of objects with url ("+regsub(req.url, "^/url/", "")+") done.";! }! }! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 62
  • 63. !   Novactive !   Reverse Proxy ! Varnish eZ Publish Architecture ! Varnish Basics ! Varnish Advanced #1 Summary !   ESI Basics !   ESI for eZ Publish ! Recursive ESI ! Varnish purge on eZ Publish publication ! Varnish Advanced #2 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 63
  • 64. Varnish advanced #2 VCL advanced eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 64
  • 65. Varnish advanced #2 Pool of backend !   random director www_director random {! {! .backend = web1;! .weight = 1;! } "! {! .backend = web2;! .weight = 1;! }! }! ! !   Don’t forget to add the second backend backend web2 {! ".host = "localhost";! ".port = "80";! } ! !   Change the backend set req.backend = www_director; ! ! ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 65
  • 66. Varnish advanced #2 Check the heath of your backend !   Poke your backend every N seconds !   Affects backend selection backend web1 {! .host = "localhost";! .port = "80";! .probe = {! .url = "/";! .interval = 3s;! .window = 5;! .threshold = 2;! }! }! !   Varnish doesn’t send Host with health checks. .probe = { ! .request =! "GET / HTTP/1.1"! "Host: www.foo.bar"! "Connection: close"; ! !   Don’t set the eZ Publish home page for the probe. eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 66
  • 67. Varnish advanced #2 Check the heath of your backend !   req.grace (in the vcl_recv) !   accept serving 30 minutes old object # set the grace! set req.grace = 30m; ! !   beresp.grace (in the vcl_fetch) !   keep all objects for 30 minutes beyond their TTL # set the grace! Set beresp.grace = 30m;! !   It’s like the “Stale cache” eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 67
  • 68. Varnish advanced #2 RewriteRule !   Varnish can do it sub vcl_recv {! ! … some rules …! ! if ( req.url ~ "^/layout/(.[^/]*)/([0-9]*)(.*)$" ) {! set req.url = regsub( ! " " "req.url, ! " " ""^/layout/(.[^/]*)/([0-9]*)(.*)$", ! " " ""/layout/set/1/content/view/full/23”! " ");! }! ! … some rules …! ! } ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 68
  • 69. Varnish advanced #2 Do a 301 HTTP redirection sub vcl_recv {! ! … some rules …! ! if (req.http.host ~ "agreatbutlongdns.ezsc" ) {! error 301 "ezpublish4.ezsc"; #see vcl_error! }! … some rules …! ! }! ! sub vcl_error {! … some rules …! if (obj.status == 301) {! set obj.http.Location = "http://" + obj.response + ":" + server.port + req.url;! } else {! … some rules …! }! }! ! ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 69
  • 70. Varnish advanced #2 Usage eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 70
  • 71. Varnish advanced #2 varnishlog eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 71
  • 72. Varnish advanced #2 varnishlog !   quite extensive !   filter information you need !   Useful to debug what happens !   And valid your configuration Best options !   –o : group by request !   -b : only show traffic related to a backend !   -c : only show traffic related to a client !   -i <tag> : only show one tag eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 72
  • 73. Varnish advanced #2 varnishtop !   Useful to know some real-time information !   top URLs sent to the client !   top URLs sent to the backend eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 73
  • 74. Varnish advanced #2 varnishncsa !   It allows you to log client access as Apache do !   NCSA log file example 127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/Getting-Started/Selected- Features HTTP/1.1" 200 4314 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"! 127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/content/view/tagcloud/2 HTTP/1.1" 200 3371 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"! 127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/content/view/sitemap/2 HTTP/1.1" 200 3187 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"! 127.0.0.1 - - [29/Aug/2012:03:50:02 +0200] "GET http://ezpublish4.ezsc:8080/content/advancedsearch HTTP/1.1" 200 4505 "-" "JoeDog/1.00 [en] (X11; I; Siege 2.70)"}! ! ! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 74
  • 75. Varnish advanced #2 varnishstat !   Perfect tool to get a good representation of your Varnish health !   Some useful statistic !   Uptime !   HIT rate !   Client connections accepted !   Client connections received !   Cache HIT !   Cache MISS !   Failed backend connections eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 75
  • 76. Varnish advanced #2 varnishstat eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 76
  • 77. Varnish advanced #2 ! Find the URL the most sent to the backend Varnistop –i TxURL! ! ! ! Find the URL the most asked by the client Varnistop –i TxURL! ! ! !   Have you try the « -j » option of varnishstats !   new in 3.03 since 08/20/12 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 77
  • 78. Varnish advanced #2 Daemon configuration eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 78
  • 79. Varnish advanced #2 BAN Console !   Access !   varnishadm !   telnet localhost 6082 !   Tunable paramaters !   param.show –l !   Be careful about the thread parameters !  root@ezsc ~ # varnishadm param.show | grep thread! cc_command "exec gcc -std=gnu99 -g -O2 -pthread -fpic -shared -Wl,-x -o %o %s"! thread_pool_add_delay 2 [milliseconds]! thread_pool_add_threshold 2 [requests]! thread_pool_fail_delay 200 [milliseconds]! thread_pool_max 2000 [threads]! thread_pool_min 1 [threads]! thread_pool_purge_delay 1000 [milliseconds]! thread_pool_stack 65536 [bytes]! thread_pool_timeout 120 [seconds]! thread_pool_workspace 16384 [bytes]! thread_pools 2 [pools]! thread_stats_rate 10 [requests]! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 79
  • 80. Varnish advanced #2 Threading parameters !   Number of threads !   how many requests Varnish can serve concurrently !   Minimum threads running = thread_pools * thread_pool_min !  2 * 1 = 2 !   Maximum threads running = thread_pool_max !   2000 !   Don’t forget to add your configuration in the default configuration !   /etc/default/varnish eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 80
  • 81. Varnish advanced #2 Real-time configuration changes !   you can change a param with varnishadm !   but don’t forget to add the new parameter value in the daemon file configuration !   About the VCL, be careful because a restart empties the cache !   Varnish don’t keep cache !   very bad idea in a production environment ! !   So let’s use varnishadm in order to reload the VCL eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 81
  • 82. To sum up… eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 82
  • 83. To sum up On the network administration side, you know !   How to set architecture of your plateform !   How to configure your Varnish !   How to optimize the daemon !   How to optimize your VCL !   How to troubleshoot your instance eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 83
  • 84. To sum up On the developer side, you know !   How to make a good conception with ESI content view !   How to remove cache-block and unleash your instance !   How to purge cache on publication eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 84
  • 85. Conclusion eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 85
  • 86. Conclusion Achieved objectives !   You can now have a production website with !   98% of requests cached by Varnish !   2 % of traffic handle by your webserver farm !   Set a architecture with !   A database dedicated to the backoffice and to the generation on new content !   A very low usage of your NFS ! Beyond speed, more security ! Your website is all the time available due to the shield protection of Varnish ! even if we have server problems eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 86
  • 87. eZ Accelerator To go further, discover eZ Accelerator available on the eZ Market Key Features !   Full support of URLs !   URL Translator, Siteaccess, PathPrefix, StaleCache etc.. ! Asynchronous purge !   Multi varnish architecture !   Cache purge on content publication ! Dedicated interface to manage your Varnish servers eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 87
  • 88. What about eZ Publish 5 eZ Publish 5 with Varnish ! Varnish on Symfony 2 ! Totally integrated with the HTTP Cache system !   ESI are directly handled by the template and cache system ! Two caching models !   Expiration model ! Based on the TTL !   Validation model ! Based on eTag ! Always the same rule : Never generate the same response twice ! !   So all the concept seen on this workshop are relevant with eZ Publish 5 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 88
  • 89. Questions ? eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 89
  • 90. Thank you! eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 90
  • 91. Adresse : 42-44, rue de Paradis 75010 PARIS Téléphone : 01.48.24.33.60 Fax : 01.48.24.33.54 Email : info@novactive.com Site : www.novactive.com SARL au capital de 132.576 euros RCS Paris B 408 999 233 eZ Summer Camp – eZ Publish Varnish Integration – Sébastien Morel 06/09/2012 91