SlideShare une entreprise Scribd logo
1  sur  69
Télécharger pour lire hors ligne
Mike Willbanks | Barnes & Noble


Varnish Cache
Housekeeping…
•  Talk
   –  Slides will be posted after the talk.
•  Me
   –  Sr. Web Architect Manager at NOOK
      Developer
   –  Prior MNPHP Organizer
   –  Open Source Contributor
   –  Where you can find me:
        •  Twitter: mwillbanks           G+: Mike Willbanks
        •  IRC (freenode): mwillbanks Blog:
           http://blog.digitalstruct.com
        •  GitHub: https://github.com/mwillbanks
Agenda
•    Varnish?
•    The Good : Getting Started
•    The Awesome : General Usage
•    The Crazy : Advanced Usage
•    Gotchas
Official Statement
What it does
General use case



WHAT IS VARNISH?
Official Statement
“Varnish is a web application accelerator. You install
 it in front of your web application and it will speed it
                     up significantly.”
You can cache…
Both dynamic and static files and contents.
A Scenario
•  System Status Server
  –  Mobile apps check current status.
  –  If the system is down do we communicate?
  –  If there are problems do we communicate?
  –  The apps and mobile site rely on an API
    •  Trouble in paradise? Few and far in between.
The Graph - AWS
               Req/s                                               Peak Load
700                                              14
600                                              12
500                                              10
400                                               8
300                                     Req/s                                                  Peak Load
                                                  6
200                                               4
100
                                                  2
  0
                                                  0
      Small   X-Large   Small Varnish
                                                          Small    X-Large    Small Varnish

                Time                                               Requests
500                                             80000
450                                             70000
400
                                                60000
350
300                                             50000
250                                             40000
                                        Time                                                    Requests
200                                             30000
150
                                                20000
100
 50                                             10000
  0                                                   0
      Small   X-Large   Small Varnish                      Small    X-Large    Small Varnish
The Raw Data
                 Small	
     X-­‐Large	
            Small	
  Varnish	
  
Concurrency	
   10	
         150	
                  150	
  
Requests	
       5000	
      55558	
                75000	
  
Time	
           438	
       347	
                  36	
  
Req/s	
          11.42	
     58	
                   585	
  
Peak	
  Load	
   11.91	
     8.44	
                 0.35	
  
                             19,442	
  failed	
  
Comments	
                   requests	
  
Load Balancer




              HTTP Server Cluster




                   Database




Traditional LAMP Stack
Load Balancer




                                                    Yes
               Varnish Cache            Cache Hit



                                          No


             HTTP Server Cluster




                  Database




LAMP + Varnish
* Varnish can act as a load balancer.
Installation
General Information
Default VCL

THE GOOD – JUMP START
Installation
rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/
noarch/varnish-release-3.0-1.noarch.rpm
yum install varnish



curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -
echo "deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-3.0" | sudo
tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install varnish


git clone git://git.varnish-cache.org/varnish-cache
cd varnish-cache
sh autogen.sh
./configure
make && make install
Varnish Daemon
•  varnishd
  –  -a address[:port] listen for client
  –  -b address[:port] backend requests
  –  -T address[:port] administration http
  –  -s type[,options]     storage type (malloc, file,
     persistence)
  –  -P /path/to/file   PID file
  –  Many others; these are generally the most
     important. Generally the defaults will do with
     just modification of the default VCL (more on it
     later).
General Configuration
•  varnishd -a :80 
      -T localhost:6082 
      -f /path/to/default.vcl 
      -s malloc,512mb
•  Web server to listen on port 8080
Setup a backend!
backend default {
    .host = “127.0.0.1”
    .port = “8080”
}
So what’s actually caching?
•  Any requests containing
  –  GET / HEAD
  –  TTL > 0
•  What cause it to miss?
  –  Cookies
  –  Authentication Headers
  –  Vary “*”
  –  Cache-control: private
Request




                                                        req.
                                           vcl_recv



            req.                 req.                                        req.
           bereq.               bereq.                   req.               bereq.
vcl_pass            vcl_miss               vcl_hash              vcl_pipe




                                 req.
                                                         req.
                                bereq.
                    vcl_fetch               vcl_hit       obj.
                                beresp.



                                                         resp.
                                          vcl_deliver




                                          Response
HTTP Caching
•  RFC 2616 HTTP/1.1 Headers
  –  Expiration
     •  Cache-Control
     •  Expires
  –  Validation
     •  Last Modified
     •  If-Modified-Since
     •  ETag
     •  If-None-Match
TTL Priority
•  VCL
  –  beresp.ttl
•  Headers
  –  Cache-control: s-max-age
  –  Cache-control: max-age
  –  Expires
  –  Validation
Use Wordpress?
backend default {
   .host = "127.0.0.1“;
   .port = "8080";
 }
sub vcl_recv {
     if (!(req.url ~ "wp-(login|admin)")) {
         unset req.http.cookie;
     }
 }
sub vcl_fetch {
     if (!(req.url ~ "wp-(login|admin)")) {
         unset beresp.http.set-cookie;
     }
 }
VCL
Directors
Verifying VCL



THE AWESOME – VCL,
DIRECTORS AND MORE
Varnish Configuration
             Language
•  VCL State Engine
   –  Each Request is Processed Separately &
      Independently
   –  States are Isolated but are Related
   –  Return statements exit one state and start another
   –  VCL defaults are ALWAYS appended below your own
      VCL
•  VCL can be complex, but…
   –  Two main subroutines; vcl_recv and vcl_fetch
   –  Common actions: pass, hit_for_pass, lookup, pipe,
      deliver
   –  Common variables: req, beresp and obj
   –  More subroutines, functions and complexity can arise
      dependent on condition.
Request




                                                        req.
                                           vcl_recv



            req.                 req.                                        req.
           bereq.               bereq.                   req.               bereq.
vcl_pass            vcl_miss               vcl_hash              vcl_pipe




                                 req.
                                                         req.
                                bereq.
                    vcl_fetch               vcl_hit       obj.
                                beresp.



                                                         resp.
                                          vcl_deliver




                                          Response
VCL - Process
VCL Process   Description
vcl_init      Startup routine (VCL loaded, VMOD init)
vcl_recv      Beginning of request, req is in scope
vcl_pipe      Client & backend data passed unaltered
vcl_pass      Request goes to backend and not cached
vcl_hash      Creates cache hash, call hash_data for custom hashes
vcl_hit       Called when hash found in cache
vcl_miss      Called when hash not found in cache
vcl_fetch     Called to fetch data from backend
vcl_deliver   Called prior to delivery of response (excluding pipe)
vcl_error     Called when an error occurs
vcl_fini      Shutdown routine (VCL unload, VMOD cleanup)
VCL – Variables
•  Always Available                •  Backend
    –  now – epoch time                –  bereq – backend request
•  Backend Declarations                –  beresp – backend response
    –  .host – hostname / IP       •  Cached Object
    –  .port – port number             –  obj – Cached object, can
•  Request Processing                     only change .ttl
    –  client – ip & identity      •  Response
    –  server – ip & port              –  resp – response information
    –  req – request information
VCL - Functions
VCL Function                    Description
hash_data(string)               Adds a string to the hash input
regsub(string, regex, sub)      Substitution on first occurrence
regsuball(string, regex, sub)   Substitution on all occurrences
ban(expression)                 Ban all items that match expression
ban(regex)                      Ban all items that match regular expression
Request




                                                                                   req.
                                                                      vcl_recv



                                       req.                 req.                                        req.
                                      bereq.               bereq.                   req.               bereq.
                           vcl_pass            vcl_miss               vcl_hash              vcl_pipe




                                                            req.
                                                                                    req.
                                                           bereq.
                                               vcl_fetch               vcl_hit       obj.
                                                           beresp.



                                                                                    resp.
                                                                     vcl_deliver

Walking through the noteworthy items.

DEFAULT VCL                                                          Response
vcl_recv
•  Received Request
•  Only GET & HEAD by default
  –  Safest way to cache!
•  Will use HTTP cache headers.
•  Cookies or Authentication Headers will
   bust out of the cache.
vcl_hash
•  Hash is what we look for in the cache.
•  Default is URL + Host
  –  Server IP used if host header was not set;
     in a load balanced environment ensure you
     set this header!
vcl_fetch
•  Fetch retrieves the response from the
   backend.
•  No Cache if…
  –  TTL is not set or not greater than 0.
  –  Vary headers exist.
  –  Hit-For-Pass means we will cache a pass
     through.
Common adjustments to make.

GENERAL ADJUSTMENTS
Cache Static Content
No reason that static content should not be cached.
Remove GA Cookies
GA cookies will cause a miss; remove them prior to going to the
backend.
Allow Purging
Only allow from localhost or trusted server network.
Leveraging backend servers

DIRECTORS
Directors – The Types
Director Type        Description
Random               Picks based on random and weight.
Client               Picks based on client identity.
Hash                 Picks based on hash value.
Round Robin          Goes in order and starts over
DNS                  Picks based on incoming DNS host,
                     random OR round robin.
Fallback             Picks the first “healthy” server.
Director - Probing
•  Backend Probing
•  Variables
  –  .url
  –  .request
  –  .window
  –  .threshold
  –  .intial
  –  .expected_response
  –  .interval
  –  .timeout
Load Balancing
Implementing a simple varnish load balancer.
Varnish does not handle SSL termination.
Grace Mode
Request already pending for update; serve grace content.
Backend is unhealthy.
Probes as seen earlier must be implemented.
Saint Mode
Backend may be sick for a particular piece of content
Saint mode makes sure that the backend will not request the object
again for a specific period of time.
Purging
•  The various ways of purging
  –  varnishadm – command line utility
  –  Sockets (port 6082)
  –  HTTP – now that is the sexiness
Purging Examples
varnishadm -T 127.0.0.1:6082 purge req.url == "/foo/bar“

telnet localhost 6082
purge req.url == "/foo/bar

telnet localhost 80
Response:
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

PURGE /foo/bar HTTP/1.0
Host: bacon.org

curl –X PURGE http://bacon.org/foo/bar
Distributed Purging
•  curl multi-request (in php)
•  Use a message queue
   –  Use workers to do the leg work for you
•  You will need to store a list of servers “somewhere”
Logging
•  Many times people want to log the
   requests to a file
  –  By default Varnish only stores these in
     shared memory.
  –  Apache Style Logs
     •  varnishncsa –D –a –w log.txt
  –  This will run as a daemon to log all of your
     requests on a separate thread.
Logging
Apache style logging using: varnishncsa -O -a -w log.txt
You likely want to ensure that your cache is:
1.  Working Properly
2.  Caching Effectively

VERIFY YOUR VCL
What is Varnish doing…
Varnishtop will show you real time information on your system.
•  Use -i to filter on specific tags.
•  Use -x to exclude specific tags.
Checking Statistics…
Varnishstat will give you statistics you need to know how you’re
doing.
ESI – Edge-Side Includes
Varnish Administration
VMOD

THE CRAZY
ESI – Edge Side Includes
•  ESI is a small markup language much like
   SSI (server side includes) to include
   fragments (or dynamic content for that
   matter).
•  Think of it as replacing regions inside of a
   page as if you were using XHR (AJAX) but
   single threaded.
•  Three Statements can be utilized.
  –  esi:include – Include a page
  –  esi:remove – Remove content
  –  <!-- esi --> - ESI disabled, execute normally
<esi:include
  src="header.php" />

                                      V                       B
                                      a                       a
                                      r                       c
                                      n                       k
                                      i                       e
     Page Content                     s                       n
                                      h                       d




ESI Diagram
Varnish detects ESI, requests from backend OR checks cached
state.
Using ESI
•  In vcl_fetch, you must set ESI to be on
  –  set beresp.do_esi = true;
  –  Varnish refuses to parse content for ESI if
     it does not look like XML
     •  This is by default; so check varnishstat and
        varnishlog to ensure that it is functioning like
        normal.
ESI Usage
<html>
    <head><title>Rock it with ESI</title></head>
    <body>
        <header>
            <esi:include src=”header.php" />
        </header>
        <section id="main">...</section>
        <footer></footer>
    </body>
</html>
Embedding C in VCL
•  Before getting into VMOD; did you know
   you can embed C into the VCL for
   varnish?
•  Want to do something crazy fast or
   leverage a C library for pre or post
   processing?
•  I know… you’re thinking that’s useless..
  –  On to the example; and a good one from
     the Varnish WIKI!
Embedded C for syslog
C{
     #include <syslog.h>
}C

sub vcl_something {
    C{
        syslog(LOG_INFO, "Something happened at VCL line XX.");
    }C
}
# Example with using varnish variables
C{
    syslog(LOG_ERR, "Spurious response from backend: xid %s request %s
   %s "%s" %d "%s" "%s"", VRT_r_req_xid(sp),
   VRT_r_req_request(sp), VRT_GetHdr(sp, HDR_REQ, "005host:"),
   VRT_r_req_url(sp), VRT_r_obj_status(sp), VRT_r_obj_response(sp),
   VRT_GetHdr(sp, HDR_OBJ, "011Location:"));
}C
Varnish Modules / Extensions
•  Taking VCL embedded C to the next
   level
•  Allows you to extend varnish and create
   new functions
•  You could link to libraries to provide
   additional functionality
VMOD - std
•    toupper           •    syslog
•    tolower           •    fileread
•    set_up_tos        •    duration
•    random            •    integer
•    log               •    collect
Management Console
Cache Warm up

ADMINISTERING VARNISH
Management Console
•  varnishadm –T localhost:6062
  –  vcl.list – see all loaded configuration
  –  vcl.load – load new configuration
  –  vcl.use – select configuration to use
  –  vcl.discard – remove configuration
Cache Warmup
•  Need to warm up your cache before
   putting a sever in the queue or load test
   an environment?
  –  varnishreplay –r log.txt
Having Keep-Alive off
No SSL Termination
No persistent cache
ESI multiple fragments
Cookies*

GOTCHAS
These slides will be posted to SlideShare & SpeakerDeck.
   SpeakerDeck: http://speakerdeck.com/u/mwillbanks
   Slideshare: http://www.slideshare.net/mwillbanks
   Twitter: mwillbanks
   G+: Mike Willbanks
   IRC (freenode): mwillbanks
   Blog: http://blog.digitalstruct.com
   GitHub: https://github.com/mwillbanks




QUESTIONS?

Contenu connexe

Tendances

Towards Scalable Service Composition on Multicores
Towards Scalable Service Composition on MulticoresTowards Scalable Service Composition on Multicores
Towards Scalable Service Composition on MulticoresCesare Pautasso
 
Chef - Evolving with Infrastructure Automation
Chef - Evolving with Infrastructure AutomationChef - Evolving with Infrastructure Automation
Chef - Evolving with Infrastructure AutomationNathaniel Brown
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Rich Bowen
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on InfinispanLance Ball
 
Spring into rails
Spring into railsSpring into rails
Spring into railsHiro Asari
 
What I did in My Internship @ WSO2
What I did in My Internship @ WSO2What I did in My Internship @ WSO2
What I did in My Internship @ WSO2Andun Sameera
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011Lance Ball
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyBruno Oliveira
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled CucumbersJoseph Wilk
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018Charles Nutter
 
My internship presentation at WSO2
My internship presentation at WSO2My internship presentation at WSO2
My internship presentation at WSO2Prabhath Suminda
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011tobiascrawley
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torqueboxrockyjaiswal
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011tobiascrawley
 

Tendances (17)

Towards Scalable Service Composition on Multicores
Towards Scalable Service Composition on MulticoresTowards Scalable Service Composition on Multicores
Towards Scalable Service Composition on Multicores
 
Chef - Evolving with Infrastructure Automation
Chef - Evolving with Infrastructure AutomationChef - Evolving with Infrastructure Automation
Chef - Evolving with Infrastructure Automation
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010Apache Cookbook - TekX Chicago 2010
Apache Cookbook - TekX Chicago 2010
 
DataMapper on Infinispan
DataMapper on InfinispanDataMapper on Infinispan
DataMapper on Infinispan
 
Spring into rails
Spring into railsSpring into rails
Spring into rails
 
First Day With J Ruby
First Day With J RubyFirst Day With J Ruby
First Day With J Ruby
 
What I did in My Internship @ WSO2
What I did in My Internship @ WSO2What I did in My Internship @ WSO2
What I did in My Internship @ WSO2
 
TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011TorqueBox - Ruby Hoedown 2011
TorqueBox - Ruby Hoedown 2011
 
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e RubyTorqueBox - Ultrapassando a fronteira entre Java e Ruby
TorqueBox - Ultrapassando a fronteira entre Java e Ruby
 
Rocket Fuelled Cucumbers
Rocket Fuelled CucumbersRocket Fuelled Cucumbers
Rocket Fuelled Cucumbers
 
The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018The Year of JRuby - RubyC 2018
The Year of JRuby - RubyC 2018
 
My internship presentation at WSO2
My internship presentation at WSO2My internship presentation at WSO2
My internship presentation at WSO2
 
Torquebox OSCON Java 2011
Torquebox OSCON Java 2011Torquebox OSCON Java 2011
Torquebox OSCON Java 2011
 
At Scale With Style
At Scale With StyleAt Scale With Style
At Scale With Style
 
When Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of TorqueboxWhen Ruby Meets Java - The Power of Torquebox
When Ruby Meets Java - The Power of Torquebox
 
Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011Torquebox @ Raleigh.rb - April 2011
Torquebox @ Raleigh.rb - April 2011
 

En vedette

Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Mike Willbanks
 
International Social Media Trends
International Social Media TrendsInternational Social Media Trends
International Social Media TrendsSueGrant
 
Balance and Flow through the 5 elements in game design
Balance and Flow through the 5 elements in game designBalance and Flow through the 5 elements in game design
Balance and Flow through the 5 elements in game designClint Walters
 
Soft Launch an Institutional Eportfolio Initiative
Soft Launch an Institutional Eportfolio InitiativeSoft Launch an Institutional Eportfolio Initiative
Soft Launch an Institutional Eportfolio InitiativeElizabeth Nesius
 
Brand Strategy Overview For Nbbn
Brand Strategy Overview For NbbnBrand Strategy Overview For Nbbn
Brand Strategy Overview For NbbnJeffrey Drake
 
How will You Measure the Worth of Your Life - UMHB
How will You Measure the Worth of Your Life - UMHBHow will You Measure the Worth of Your Life - UMHB
How will You Measure the Worth of Your Life - UMHBSam Henry
 
Les 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van OrganisatiesLes 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van OrganisatiesMediena Business School
 
Leveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push NotificationsLeveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push NotificationsMike Willbanks
 
第10-11週
第10-11週第10-11週
第10-11週fudy9015
 
Law & grace
Law & graceLaw & grace
Law & graceGeo Acts
 
4th grade curriculum night classroom 10 11
4th grade curriculum night classroom  10 114th grade curriculum night classroom  10 11
4th grade curriculum night classroom 10 11Bret Biornstad
 
Mortel Scooter Campaign
Mortel Scooter CampaignMortel Scooter Campaign
Mortel Scooter Campaignsdelastic
 
Bideo-Jolasak
Bideo-JolasakBideo-Jolasak
Bideo-Jolasakolatzucin
 
Retrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s YearRetrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s Yearsdelastic
 
Europa Del Settecento
Europa Del SettecentoEuropa Del Settecento
Europa Del Settecentomapaa
 
Dec 06, Sermon Am
Dec 06, Sermon AmDec 06, Sermon Am
Dec 06, Sermon AmGeo Acts
 
Welcome To Msp Information Night 2010
Welcome To Msp Information Night 2010Welcome To Msp Information Night 2010
Welcome To Msp Information Night 2010Bret Biornstad
 

En vedette (20)

Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012
 
International Social Media Trends
International Social Media TrendsInternational Social Media Trends
International Social Media Trends
 
Balance and Flow through the 5 elements in game design
Balance and Flow through the 5 elements in game designBalance and Flow through the 5 elements in game design
Balance and Flow through the 5 elements in game design
 
5 things MySql
5 things MySql5 things MySql
5 things MySql
 
Soft Launch an Institutional Eportfolio Initiative
Soft Launch an Institutional Eportfolio InitiativeSoft Launch an Institutional Eportfolio Initiative
Soft Launch an Institutional Eportfolio Initiative
 
Brand Strategy Overview For Nbbn
Brand Strategy Overview For NbbnBrand Strategy Overview For Nbbn
Brand Strategy Overview For Nbbn
 
How will You Measure the Worth of Your Life - UMHB
How will You Measure the Worth of Your Life - UMHBHow will You Measure the Worth of Your Life - UMHB
How will You Measure the Worth of Your Life - UMHB
 
Les 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van OrganisatiesLes 1 Inleiding En Functioneren Van Organisaties
Les 1 Inleiding En Functioneren Van Organisaties
 
Leveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push NotificationsLeveraging Zend Framework for Sending Push Notifications
Leveraging Zend Framework for Sending Push Notifications
 
第10-11週
第10-11週第10-11週
第10-11週
 
Law & grace
Law & graceLaw & grace
Law & grace
 
4th grade curriculum night classroom 10 11
4th grade curriculum night classroom  10 114th grade curriculum night classroom  10 11
4th grade curriculum night classroom 10 11
 
5th Grade
5th Grade5th Grade
5th Grade
 
Mortel Scooter Campaign
Mortel Scooter CampaignMortel Scooter Campaign
Mortel Scooter Campaign
 
Bideo-Jolasak
Bideo-JolasakBideo-Jolasak
Bideo-Jolasak
 
Retrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s YearRetrospective 2008 The Surfer’s Year
Retrospective 2008 The Surfer’s Year
 
Europa Del Settecento
Europa Del SettecentoEuropa Del Settecento
Europa Del Settecento
 
Dec 06, Sermon Am
Dec 06, Sermon AmDec 06, Sermon Am
Dec 06, Sermon Am
 
Mohammed Farrag Resume
Mohammed Farrag ResumeMohammed Farrag Resume
Mohammed Farrag Resume
 
Welcome To Msp Information Night 2010
Welcome To Msp Information Night 2010Welcome To Msp Information Night 2010
Welcome To Msp Information Night 2010
 

Similaire à Varnish Cache - International PHP Conference Fall 2012

Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Mike Willbanks
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyLeif Hedstrom
 
Resin Outperforms NginX
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginXbilldigman
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - DeploymentFabio Akita
 
Altitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and ClusteringAltitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and ClusteringFastly
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & ScalabilityJoseph Scott
 
Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSamantha Quiñones
 
Varnish
VarnishVarnish
VarnishAdyax
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesSeveralnines
 
vert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMvert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMjbandi
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmospherejfarcand
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011Kris Mok
 
Full Stack Load Testing
Full Stack Load Testing Full Stack Load Testing
Full Stack Load Testing Terral R Jordan
 

Similaire à Varnish Cache - International PHP Conference Fall 2012 (20)

Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.Varnish, The Good, The Awesome, and the Downright Crazy.
Varnish, The Good, The Awesome, and the Downright Crazy.
 
Usenix lisa 2011
Usenix lisa 2011Usenix lisa 2011
Usenix lisa 2011
 
Apache con 2011 gd
Apache con 2011 gdApache con 2011 gd
Apache con 2011 gd
 
Usenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a ProxyUsenix LISA 2012 - Choosing a Proxy
Usenix LISA 2012 - Choosing a Proxy
 
Resin Outperforms NginX
Resin Outperforms NginXResin Outperforms NginX
Resin Outperforms NginX
 
Deployment de Rails
Deployment de RailsDeployment de Rails
Deployment de Rails
 
Fisl - Deployment
Fisl - DeploymentFisl - Deployment
Fisl - Deployment
 
Altitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and ClusteringAltitude SF 2017: Advanced VCL: Shielding and Clustering
Altitude SF 2017: Advanced VCL: Shielding and Clustering
 
Cold Hard Cache
Cold Hard CacheCold Hard Cache
Cold Hard Cache
 
Nginx
NginxNginx
Nginx
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
 
Supercharging Content Delivery with Varnish
Supercharging Content Delivery with VarnishSupercharging Content Delivery with Varnish
Supercharging Content Delivery with Varnish
 
Varnish Cache
Varnish CacheVarnish Cache
Varnish Cache
 
Varnish
VarnishVarnish
Varnish
 
Load Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - SlidesLoad Balancing MySQL with HAProxy - Slides
Load Balancing MySQL with HAProxy - Slides
 
vert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVMvert.x - asynchronous event-driven web applications on the JVM
vert.x - asynchronous event-driven web applications on the JVM
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmosphere
 
JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011JVM @ Taobao - QCon Hangzhou 2011
JVM @ Taobao - QCon Hangzhou 2011
 
Full Stack Load Testing
Full Stack Load Testing Full Stack Load Testing
Full Stack Load Testing
 

Plus de Mike Willbanks

2015 ZendCon - Do you queue
2015 ZendCon - Do you queue2015 ZendCon - Do you queue
2015 ZendCon - Do you queueMike Willbanks
 
ZF2: Writing Service Components
ZF2: Writing Service ComponentsZF2: Writing Service Components
ZF2: Writing Service ComponentsMike Willbanks
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2Mike Willbanks
 
Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012Mike Willbanks
 
Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Mike Willbanks
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleMike Willbanks
 
Zend Framework Push Notifications
Zend Framework Push NotificationsZend Framework Push Notifications
Zend Framework Push NotificationsMike Willbanks
 
Mobile Push Notifications
Mobile Push NotificationsMobile Push Notifications
Mobile Push NotificationsMike Willbanks
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend FrameworkMike Willbanks
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011Mike Willbanks
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKXMike Willbanks
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101Mike Willbanks
 
The Art of Message Queues
The Art of Message QueuesThe Art of Message Queues
The Art of Message QueuesMike Willbanks
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database DeploymentsMike Willbanks
 

Plus de Mike Willbanks (16)

2015 ZendCon - Do you queue
2015 ZendCon - Do you queue2015 ZendCon - Do you queue
2015 ZendCon - Do you queue
 
ZF2: Writing Service Components
ZF2: Writing Service ComponentsZF2: Writing Service Components
ZF2: Writing Service Components
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2
 
Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012Message Queues : A Primer - International PHP Conference Fall 2012
Message Queues : A Primer - International PHP Conference Fall 2012
 
Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)Push to Me: Mobile Push Notifications (Zend Framework)
Push to Me: Mobile Push Notifications (Zend Framework)
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
 
Zend Framework Push Notifications
Zend Framework Push NotificationsZend Framework Push Notifications
Zend Framework Push Notifications
 
Mobile Push Notifications
Mobile Push NotificationsMobile Push Notifications
Mobile Push Notifications
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend Framework
 
MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011MNPHP Scalable Architecture 101 - Feb 3 2011
MNPHP Scalable Architecture 101 - Feb 3 2011
 
The Art of Message Queues - TEKX
The Art of Message Queues - TEKXThe Art of Message Queues - TEKX
The Art of Message Queues - TEKX
 
Art Of Message Queues
Art Of Message QueuesArt Of Message Queues
Art Of Message Queues
 
Scalable Architecture 101
Scalable Architecture 101Scalable Architecture 101
Scalable Architecture 101
 
The Art of Message Queues
The Art of Message QueuesThe Art of Message Queues
The Art of Message Queues
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
LiquiBase
LiquiBaseLiquiBase
LiquiBase
 

Dernier

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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
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
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Dernier (20)

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
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
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
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
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
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
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
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

Varnish Cache - International PHP Conference Fall 2012

  • 1. Mike Willbanks | Barnes & Noble Varnish Cache
  • 2. Housekeeping… •  Talk –  Slides will be posted after the talk. •  Me –  Sr. Web Architect Manager at NOOK Developer –  Prior MNPHP Organizer –  Open Source Contributor –  Where you can find me: •  Twitter: mwillbanks G+: Mike Willbanks •  IRC (freenode): mwillbanks Blog: http://blog.digitalstruct.com •  GitHub: https://github.com/mwillbanks
  • 3. Agenda •  Varnish? •  The Good : Getting Started •  The Awesome : General Usage •  The Crazy : Advanced Usage •  Gotchas
  • 4. Official Statement What it does General use case WHAT IS VARNISH?
  • 5. Official Statement “Varnish is a web application accelerator. You install it in front of your web application and it will speed it up significantly.”
  • 6.
  • 7.
  • 8.
  • 9. You can cache… Both dynamic and static files and contents.
  • 10. A Scenario •  System Status Server –  Mobile apps check current status. –  If the system is down do we communicate? –  If there are problems do we communicate? –  The apps and mobile site rely on an API •  Trouble in paradise? Few and far in between.
  • 11. The Graph - AWS Req/s Peak Load 700 14 600 12 500 10 400 8 300 Req/s Peak Load 6 200 4 100 2 0 0 Small X-Large Small Varnish Small X-Large Small Varnish Time Requests 500 80000 450 70000 400 60000 350 300 50000 250 40000 Time Requests 200 30000 150 20000 100 50 10000 0 0 Small X-Large Small Varnish Small X-Large Small Varnish
  • 12. The Raw Data Small   X-­‐Large   Small  Varnish   Concurrency   10   150   150   Requests   5000   55558   75000   Time   438   347   36   Req/s   11.42   58   585   Peak  Load   11.91   8.44   0.35   19,442  failed   Comments   requests  
  • 13. Load Balancer HTTP Server Cluster Database Traditional LAMP Stack
  • 14. Load Balancer Yes Varnish Cache Cache Hit No HTTP Server Cluster Database LAMP + Varnish * Varnish can act as a load balancer.
  • 16. Installation rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/ noarch/varnish-release-3.0-1.noarch.rpm yum install varnish curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add - echo "deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-3.0" | sudo tee -a /etc/apt/sources.list sudo apt-get update sudo apt-get install varnish git clone git://git.varnish-cache.org/varnish-cache cd varnish-cache sh autogen.sh ./configure make && make install
  • 17. Varnish Daemon •  varnishd –  -a address[:port] listen for client –  -b address[:port] backend requests –  -T address[:port] administration http –  -s type[,options] storage type (malloc, file, persistence) –  -P /path/to/file PID file –  Many others; these are generally the most important. Generally the defaults will do with just modification of the default VCL (more on it later).
  • 18. General Configuration •  varnishd -a :80 -T localhost:6082 -f /path/to/default.vcl -s malloc,512mb •  Web server to listen on port 8080
  • 19. Setup a backend! backend default { .host = “127.0.0.1” .port = “8080” }
  • 20. So what’s actually caching? •  Any requests containing –  GET / HEAD –  TTL > 0 •  What cause it to miss? –  Cookies –  Authentication Headers –  Vary “*” –  Cache-control: private
  • 21. Request req. vcl_recv req. req. req. bereq. bereq. req. bereq. vcl_pass vcl_miss vcl_hash vcl_pipe req. req. bereq. vcl_fetch vcl_hit obj. beresp. resp. vcl_deliver Response
  • 22. HTTP Caching •  RFC 2616 HTTP/1.1 Headers –  Expiration •  Cache-Control •  Expires –  Validation •  Last Modified •  If-Modified-Since •  ETag •  If-None-Match
  • 23. TTL Priority •  VCL –  beresp.ttl •  Headers –  Cache-control: s-max-age –  Cache-control: max-age –  Expires –  Validation
  • 24. Use Wordpress? backend default { .host = "127.0.0.1“; .port = "8080"; } sub vcl_recv { if (!(req.url ~ "wp-(login|admin)")) { unset req.http.cookie; } } sub vcl_fetch { if (!(req.url ~ "wp-(login|admin)")) { unset beresp.http.set-cookie; } }
  • 25. VCL Directors Verifying VCL THE AWESOME – VCL, DIRECTORS AND MORE
  • 26. Varnish Configuration Language •  VCL State Engine –  Each Request is Processed Separately & Independently –  States are Isolated but are Related –  Return statements exit one state and start another –  VCL defaults are ALWAYS appended below your own VCL •  VCL can be complex, but… –  Two main subroutines; vcl_recv and vcl_fetch –  Common actions: pass, hit_for_pass, lookup, pipe, deliver –  Common variables: req, beresp and obj –  More subroutines, functions and complexity can arise dependent on condition.
  • 27. Request req. vcl_recv req. req. req. bereq. bereq. req. bereq. vcl_pass vcl_miss vcl_hash vcl_pipe req. req. bereq. vcl_fetch vcl_hit obj. beresp. resp. vcl_deliver Response
  • 28. VCL - Process VCL Process Description vcl_init Startup routine (VCL loaded, VMOD init) vcl_recv Beginning of request, req is in scope vcl_pipe Client & backend data passed unaltered vcl_pass Request goes to backend and not cached vcl_hash Creates cache hash, call hash_data for custom hashes vcl_hit Called when hash found in cache vcl_miss Called when hash not found in cache vcl_fetch Called to fetch data from backend vcl_deliver Called prior to delivery of response (excluding pipe) vcl_error Called when an error occurs vcl_fini Shutdown routine (VCL unload, VMOD cleanup)
  • 29. VCL – Variables •  Always Available •  Backend –  now – epoch time –  bereq – backend request •  Backend Declarations –  beresp – backend response –  .host – hostname / IP •  Cached Object –  .port – port number –  obj – Cached object, can •  Request Processing only change .ttl –  client – ip & identity •  Response –  server – ip & port –  resp – response information –  req – request information
  • 30. VCL - Functions VCL Function Description hash_data(string) Adds a string to the hash input regsub(string, regex, sub) Substitution on first occurrence regsuball(string, regex, sub) Substitution on all occurrences ban(expression) Ban all items that match expression ban(regex) Ban all items that match regular expression
  • 31. Request req. vcl_recv req. req. req. bereq. bereq. req. bereq. vcl_pass vcl_miss vcl_hash vcl_pipe req. req. bereq. vcl_fetch vcl_hit obj. beresp. resp. vcl_deliver Walking through the noteworthy items. DEFAULT VCL Response
  • 32.
  • 33. vcl_recv •  Received Request •  Only GET & HEAD by default –  Safest way to cache! •  Will use HTTP cache headers. •  Cookies or Authentication Headers will bust out of the cache.
  • 34.
  • 35. vcl_hash •  Hash is what we look for in the cache. •  Default is URL + Host –  Server IP used if host header was not set; in a load balanced environment ensure you set this header!
  • 36.
  • 37. vcl_fetch •  Fetch retrieves the response from the backend. •  No Cache if… –  TTL is not set or not greater than 0. –  Vary headers exist. –  Hit-For-Pass means we will cache a pass through.
  • 38. Common adjustments to make. GENERAL ADJUSTMENTS
  • 39. Cache Static Content No reason that static content should not be cached.
  • 40. Remove GA Cookies GA cookies will cause a miss; remove them prior to going to the backend.
  • 41. Allow Purging Only allow from localhost or trusted server network.
  • 43. Directors – The Types Director Type Description Random Picks based on random and weight. Client Picks based on client identity. Hash Picks based on hash value. Round Robin Goes in order and starts over DNS Picks based on incoming DNS host, random OR round robin. Fallback Picks the first “healthy” server.
  • 44. Director - Probing •  Backend Probing •  Variables –  .url –  .request –  .window –  .threshold –  .intial –  .expected_response –  .interval –  .timeout
  • 45. Load Balancing Implementing a simple varnish load balancer. Varnish does not handle SSL termination.
  • 46. Grace Mode Request already pending for update; serve grace content. Backend is unhealthy. Probes as seen earlier must be implemented.
  • 47. Saint Mode Backend may be sick for a particular piece of content Saint mode makes sure that the backend will not request the object again for a specific period of time.
  • 48. Purging •  The various ways of purging –  varnishadm – command line utility –  Sockets (port 6082) –  HTTP – now that is the sexiness
  • 49. Purging Examples varnishadm -T 127.0.0.1:6082 purge req.url == "/foo/bar“ telnet localhost 6082 purge req.url == "/foo/bar telnet localhost 80 Response: Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. PURGE /foo/bar HTTP/1.0 Host: bacon.org curl –X PURGE http://bacon.org/foo/bar
  • 50. Distributed Purging •  curl multi-request (in php) •  Use a message queue –  Use workers to do the leg work for you •  You will need to store a list of servers “somewhere”
  • 51. Logging •  Many times people want to log the requests to a file –  By default Varnish only stores these in shared memory. –  Apache Style Logs •  varnishncsa –D –a –w log.txt –  This will run as a daemon to log all of your requests on a separate thread.
  • 52. Logging Apache style logging using: varnishncsa -O -a -w log.txt
  • 53. You likely want to ensure that your cache is: 1.  Working Properly 2.  Caching Effectively VERIFY YOUR VCL
  • 54. What is Varnish doing… Varnishtop will show you real time information on your system. •  Use -i to filter on specific tags. •  Use -x to exclude specific tags.
  • 55. Checking Statistics… Varnishstat will give you statistics you need to know how you’re doing.
  • 56. ESI – Edge-Side Includes Varnish Administration VMOD THE CRAZY
  • 57. ESI – Edge Side Includes •  ESI is a small markup language much like SSI (server side includes) to include fragments (or dynamic content for that matter). •  Think of it as replacing regions inside of a page as if you were using XHR (AJAX) but single threaded. •  Three Statements can be utilized. –  esi:include – Include a page –  esi:remove – Remove content –  <!-- esi --> - ESI disabled, execute normally
  • 58. <esi:include src="header.php" /> V B a a r c n k i e Page Content s n h d ESI Diagram Varnish detects ESI, requests from backend OR checks cached state.
  • 59. Using ESI •  In vcl_fetch, you must set ESI to be on –  set beresp.do_esi = true; –  Varnish refuses to parse content for ESI if it does not look like XML •  This is by default; so check varnishstat and varnishlog to ensure that it is functioning like normal.
  • 60. ESI Usage <html> <head><title>Rock it with ESI</title></head> <body> <header> <esi:include src=”header.php" /> </header> <section id="main">...</section> <footer></footer> </body> </html>
  • 61. Embedding C in VCL •  Before getting into VMOD; did you know you can embed C into the VCL for varnish? •  Want to do something crazy fast or leverage a C library for pre or post processing? •  I know… you’re thinking that’s useless.. –  On to the example; and a good one from the Varnish WIKI!
  • 62. Embedded C for syslog C{ #include <syslog.h> }C sub vcl_something { C{ syslog(LOG_INFO, "Something happened at VCL line XX."); }C } # Example with using varnish variables C{ syslog(LOG_ERR, "Spurious response from backend: xid %s request %s %s "%s" %d "%s" "%s"", VRT_r_req_xid(sp), VRT_r_req_request(sp), VRT_GetHdr(sp, HDR_REQ, "005host:"), VRT_r_req_url(sp), VRT_r_obj_status(sp), VRT_r_obj_response(sp), VRT_GetHdr(sp, HDR_OBJ, "011Location:")); }C
  • 63. Varnish Modules / Extensions •  Taking VCL embedded C to the next level •  Allows you to extend varnish and create new functions •  You could link to libraries to provide additional functionality
  • 64. VMOD - std •  toupper •  syslog •  tolower •  fileread •  set_up_tos •  duration •  random •  integer •  log •  collect
  • 65. Management Console Cache Warm up ADMINISTERING VARNISH
  • 66. Management Console •  varnishadm –T localhost:6062 –  vcl.list – see all loaded configuration –  vcl.load – load new configuration –  vcl.use – select configuration to use –  vcl.discard – remove configuration
  • 67. Cache Warmup •  Need to warm up your cache before putting a sever in the queue or load test an environment? –  varnishreplay –r log.txt
  • 68. Having Keep-Alive off No SSL Termination No persistent cache ESI multiple fragments Cookies* GOTCHAS
  • 69. These slides will be posted to SlideShare & SpeakerDeck. SpeakerDeck: http://speakerdeck.com/u/mwillbanks Slideshare: http://www.slideshare.net/mwillbanks Twitter: mwillbanks G+: Mike Willbanks IRC (freenode): mwillbanks Blog: http://blog.digitalstruct.com GitHub: https://github.com/mwillbanks QUESTIONS?