SlideShare a Scribd company logo
1 of 107
Download to read offline
Varnish 3
      The easy way
to speed up your websites




                                                               @fabpot
                                                    fabien@symfony.com
http://www.flickr.com/photos/laserstars/908946494
Varnish is an HTTP accelerator




                   http://www.flickr.com/photos/stuckincustoms/3232133635
Varnish is a Caching Reverse Proxy




                     http://www.flickr.com/photos/stuckincustoms/3232133635
Kinds of caches




                  http://www.flickr.com/photos/jnarin/2993803017
Browser            Browser             Browser
Browser Cache     Browser Cache        Browser Cache



                Within a Company




                On the server side



                Your PHP application
Browser         Browser              Browser         Browser         Browser            Browser

Browser Cache   Browser Cache        Browser Cache   Browser Cache   Browser Cache      Browser Cache



                 Proxy Cache                                          Proxy Cache

                Within a Company                                     Within a Company




                                   On the server side



                                   Your PHP application
Browser         Browser         Browser         Browser            Browser

Browser Cache   Browser Cache   Browser Cache   Browser Cache      Browser Cache



                                                 Proxy Cache

                                                Within a Company




                 On the server side
                   Reverse Proxy Cache


                  Your PHP application
HTTP and Caching




                   http://www.flickr.com/photos/hdz/5623651313
RFC 2616 – HTTP/1.1


http://www.ietf.org/rfc/rfc2616.txt
 http://tools.ietf.org/wg/httpbis/
The Client sends a Request to the Server
The Server sends back a Response to the Client

       A Client (browser, bot, WS, curl, …)
          A Server (Apache, nginx, …)
The Request and the Response are HTTP messages
GET / HTTP/1.1
Host: http.trainings.sensiolabs.com
HTTP/1.1 200 OK
Date: Wed, 15 Oct 2005 07:07:07 GMT
Server: Apache
Content-Length: 14
Content-Type: text/html

Hello World!
Caching in the HTTP Specification
 p1: Messaging: Low-level message parsing and connection
  management
 p2: Semantics: Methods, status codes and headers
 p3: Payload: Dealing with content, message-specific headers
 p4: Conditional Requests: e.g., If-Modified-Since
 p5: Range Requests: Getting partial content
 p6: Caching: Browser and intermediary caches
 p7: Authentication: HTTP authentication framework
Expiration

Cache-Control
   Expires
Validation

Last-Modified / If-Modified-Since
       ETag / If-None-Match
The goal is to never
generate the same response twice




                           http://www.flickr.com/photos/donaldmacleod/3439612846
HTTP Expiration
GET /foo HTTP/1.1                        GET /foo HTTP/1.1
          Host: foo.org                            Host: foo.org




                                                                                        Your PHP application
                                      Some Cache
Browser




                              GET /foo
                              HTTP/1.1 200 OK
                              Cache-Control: s-
                              maxage=10

                              Hello




                                                    HTTP/1.1 200 OK
           HTTP/1.1 200 OK
                                                    Cache-­‐Control:	
  s-­‐maxage=10
           Hello
                                                    Hello
Before expiration

          GET /foo HTTP/1.1                        Your application is not called
          Host: foo.org




                                                                                    Your PHP application
                                      Some Cache
Browser




                              GET /foo
                              HTTP/1.1 200 OK
                              Cache-Control: s-
                              maxage=10

                              Hello




           HTTP/1.1 200 OK

           Hello
After expiration

          GET /foo HTTP/1.1                              GET /foo HTTP/1.1
          Host: foo.org                                  Host: foo.org




                                      Some Cache fresh




                                                                                       Your PHP application
                                              Not
Browser




                              GET /foo
                              HTTP/1.1 200 OK
                              Cache-Control: s-
                              maxage=10

                              Hello




                                                          HTTP/1.1 200 OK
           HTTP/1.1 200 OK
                                                          Cache-Control: s-maxage=10
           Hello
                                                          Hello
HTTP Validation
Last-Modified / If-Modified-Since
       Etag / If-None-Match
GET /foo HTTP/1.1                                     GET /foo HTTP/1.1
          Host: foo.org                                         Host: foo.org




                                                                                               Your PHP application
                                              Some Cache
Browser




                                      GET /foo
                                      HTTP/1.1 200 OK
                                      Last-Modified: Thu,	
  
                                      …

                                      Hello




           HTTP/1.1 200 OK                                          HTTP/1.1 200 OK
           Last-Modified: Thu,	
  …                                 Last-Modified: Thu,	
  …

           Hello                                                    Hello
If the resource has not changed

                                                            GET /foo HTTP/1.1
          GET /foo HTTP/1.1
                                                            Host: foo.org
          Host: foo.org
                                                            If-Modified-Since: Thu,




                                                                                               Your PHP application
                                              Some Cache
Browser




                                      GET /foo
                                      HTTP/1.1 200 OK
                                      Last-Modified: Thu,	
  
                                      …

                                      Hello




           HTTP/1.1 200 OK                                      HTTP/1.1 304 Not Modified
           Last-Modified: Thu,	
  …

           Hello
If the resource has changed

                                                           GET /foo HTTP/1.1
          GET /foo HTTP/1.1
                                                           Host: foo.org
          Host: foo.org
                                                           If-Modified-Since: Thu,




                                                                                               Your PHP application
                                              Some Cache
Browser




                                      GET /foo /foo
                                             GET
                                      HTTP/1.1 200 200 OK
                                         HTTP/1.1 OK
                                      Last-Modified: Sun,…
                                       Last-Modified: Thu,…

                                      Hello    Hello




           HTTP/1.1 200 OK                                     HTTP/1.1 200 OK
           Last-Modified: Sun,	
  …                            Last-Modified: Sun,	
  …

           Hello                                               Hello
You can combine HTTP headers
        the way you want

Expiration wins over Validation
GET /foo HTTP/1.1                                               GET /foo HTTP/1.1
          Host: foo.org                                                   Host: foo.org




                                                                                                                 Your PHP application
                                                       Some Cache
Browser




                                             GET /foo
                                             HTTP/1.1 200 OK
                                             Etag: abcdef
                                             Cache-­‐Control:	
  max-­‐
                                             age=10
                                             …

                                             Hello




          HTTP/1.1 200 OK                                                     HTTP/1.1 200 OK
          ETag: abcdef                                                        ETag: abcdef
          Cache-­‐Control:	
  max-­‐age=10                                    Cache-­‐Control:	
  max-­‐age=10

          Hello                                                               Hello
Before expiration

          GET /foo HTTP/1.1
          Host: foo.org
                                                               Your application is not called




                                                                                                 Your PHP application
                                                       Some Cache
Browser




                                             GET /foo
                                             HTTP/1.1 200 OK
                                             Etag: abcdef
                                             Cache-­‐Control:	
  max-­‐
                                             age=10
                                             …

                                             Hello




          HTTP/1.1 200 OK
          ETag: abcdef
          Cache-­‐Control:	
  max-­‐age=10

          Hello
After expiration
                                                                                             but resource still valid

                                                                          GET /foo HTTP/1.1
          GET /foo HTTP/1.1
                                                                          Host: foo.org
          Host: foo.org
                                                                          If-None-Match: abcdef




                                                                                                                 Your PHP application
                                                       Some Cache
Browser




                                             GET /foo
                                             HTTP/1.1 200 OK
                                             Etag: abcdef
                                             Cache-­‐Control:	
  max-­‐
                                             age=10
                                             …

                                             Hello




          HTTP/1.1 200 OK                                                  HTTP/1.1 304 Not Modified
          ETag: abcdef                                                     Cache-­‐Control:	
  max-­‐age=10
          Cache-­‐Control:	
  max-­‐age=10

          Hello
HTTP Expiration
GET /foo HTTP/1.1                          GET /foo HTTP/1.1                                  GET /foo HTTP/1.1
      Host: foo.org                              Host: foo.org                                      Host: foo.org




                                                                                                                         Your PHP application
                                                                              Reverse Proxy Cache
                           GET /foo                                   GET /foo
                           HTTP/1.1 200 OK                            HTTP/1.1 200 OK
                           C-C: max-age=600                           C-C: max-age=600



                                   Bob’s Cache
                           …                                          …

                           Hello                                      Hello
Bob




        HTTP/1.1 200 OK                            HTTP/1.1 200 OK                                    HTTP/1.1 200 OK
        C-C: max-age=600                           C-C: max-age=600                                   C-C: max-age=600

        Hello                                      Hello                                              Hello
GET /foo HTTP/1.1
      Host: foo.org




                                                                               Your PHP application
                                                         Reverse Proxy Cache
                           GET /foo              GET /foo
                           HTTP/1.1 200 OK       HTTP/1.1 200 OK
                           C-C: max-age=600      C-C: max-age=600



                                   Bob’s Cache
                           …                     …

                           Hello                 Hello
Bob




        HTTP/1.1 200 OK
        C-C: max-age=600

        Hello
GET /foo HTTP/1.1                            GET /foo HTTP/1.1
        Host: foo.org                                Host: foo.org




                                                                                                        Your PHP application
                                                                                  Reverse Proxy Cache
                             GET /foo                                     GET /foo
                             HTTP/1.1 200 OK                              HTTP/1.1 200 OK




                                     Browser Cache
                             C-C: max-age=600                             C-C: max-age=600
                             …                                            …

                             Hello                                        Hello
Alice




          HTTP/1.1 200 OK                              HTTP/1.1 200 OK
          C-C: max-age=600                             C-C: max-age=600

          Hello                                        Hello
HTTP Validation
GET /foo HTTP/1.1                         GET /foo HTTP/1.1                                 GET /foo HTTP/1.1
      Host: foo.org                             Host: foo.org                                     Host: foo.org




                                                                                                                      Your PHP application
                                                                            Reverse Proxy Cache
                          GET /foo                                  GET /foo
                          HTTP/1.1 200 OK                           HTTP/1.1 200 OK
                          Etag: abcde                               Etag: abcde



                                  Bob’s Cache
                          …                                         …

                          Hello                                     Hello
Bob




        HTTP/1.1 200 OK                           HTTP/1.1 200 OK                                   HTTP/1.1 200 OK
        Etag: abcde                               Etag: abcde                                       Etag: abcde

        Hello                                     Hello                                             Hello
GET /foo HTTP/1.1                                 GET /foo HTTP/1.1
      GET /foo HTTP/1.1
                                                Host: foo.org                                     Host: foo.org
      Host: foo.org
                                                If-None-Match: ab                                 If-None-Match: ab




                                                                                                                       Your PHP application
                                                                            Reverse Proxy Cache
                          GET /foo                                  GET /foo
                          HTTP/1.1 200 OK                           HTTP/1.1 200 OK
                          Etag: ab                                  Etag: ab



                                  Bob’s Cache
                          …                                         …

                          Hello                                     Hello
Bob




        HTTP/1.1 200 OK
        Etag: ab
                                                 304 Not Modified                                   304 Not Modified
        Hello
GET /foo HTTP/1.1
        GET /foo HTTP/1.1                           GET /foo HTTP/1.1
                                                                                                      Host: foo.org
        Host: foo.org                               Host: foo.org
                                                                                                      If-None-Match: ab




                                                                                                                           Your PHP application
                                                                                Reverse Proxy Cache
                            GET /foo                                    GET /foo




                                    Browser Cache
                            HTTP/1.1 200 OK                             HTTP/1.1 200 OK
                            Etag: ab                                    Etag: ab
                            …                                           …

                            Hello                                       Hello
Alice




          HTTP/1.1 200 OK                            HTTP/1.1 200 OK
          Etag: ab                                   Etag: ab
                                                                                                        304 Not Modified
          Hello                                      Hello
VCL
Varnish Configuration Language




                           http://www.flickr.com/photos/akatayama/84707813
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}
pipe
                                                           vcl_pipe
                                                                                            error


                                                                                             vcl_error
      restart
                                                                                                    deliver

                                                orkflow
                           lookup                                                deliver
Request         vcl_recv            vcl_hash
                                               W cached?              vcl_hit
                                                                                 pass
                                                                                            vcl_deliver       Response

                                                                                                    deliver
                                                                                 fetch
                                                                      vcl_miss               vcl_fetch
                                                                                 pass



                                                                                 vcl_pass
                    pass
Special Subroutines
req.
                      pipe
                                                           vcl_pipe
                                                                                            error


                                                                                             vcl_error
        restart
                                                                                                    deliver
                             lookup                                              deliver
Request           vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                                 pass
                                                                                                    deliver
                                                                                 fetch
                                                                      vcl_miss               vcl_fetch
                                                                                 pass



                                                                                 vcl_pass
                      pass
if (req.restarts == 0) {
    if (req.http.x-forwarded-for) {
        set req.http.X-Forwarded-For =
        req.http.X-Forwarded-For + ", " + client.ip;
    } else {
        set req.http.X-Forwarded-For = client.ip;
    }
}
if (req.request != "GET" && req.request != "HEAD" && req.request !=
"PUT" && req.request != "POST" && req.request != "TRACE" &&
req.request != "OPTIONS" && req.request != "DELETE") {
    return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
    return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
    return (pass);
}
return (lookup);
req.
                      pipe
                                                           vcl_pipe
                                                                                            error


                                                                                             vcl_error
        restart
                                                                                                    deliver
                             lookup                                              deliver
Request           vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                                 pass
                                                                                                    deliver
                                                                                 fetch
                                                                      vcl_miss               vcl_fetch
                                                                                 pass



                                                                                 vcl_pass
                      pass
hash_data(req.url);
if (req.http.host) {
    hash_data(req.http.host);
} else {
    hash_data(server.ip);
}
return (hash);
pipe
                                                         vcl_pipe
                                                                                          error


                                                                                           vcl_error
      restart
                                                                                                  deliver
                           lookup                                              deliver
Request         vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                               pass
                                                                                                  deliver
                                                                               fetch
                                                                    vcl_miss               vcl_fetch
                                                                               pass



                                                                               vcl_pass
                    pass
req.
 obj.
                      pipe
                                                           vcl_pipe
                                                                                            error


                                                                                             vcl_error
        restart
                                                                                                    deliver
                             lookup                                              deliver
Request           vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                                 pass
                                                                                                    deliver
                                                                                 fetch
                                                                      vcl_miss               vcl_fetch
                                                                                 pass



                                                                                 vcl_pass
                      pass
return (deliver);
req.
 bereq.
                    pipe
                                                         vcl_pipe
                                                                                          error


                                                                                           vcl_error
      restart
                                                                                                  deliver
                           lookup                                              deliver
Request         vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                               pass
                                                                                                  deliver
                                                                               fetch
                                                                    vcl_miss               vcl_fetch
                                                                               pass



                                                                               vcl_pass
                    pass
return (fetch);
req.
 bereq.
 beresp.            pipe
                                                         vcl_pipe
                                                                                          error


                                                                                           vcl_error
      restart
                                                                                                  deliver
                           lookup                                              deliver
Request         vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                               pass
                                                                                                  deliver
                                                                               fetch
                                                                    vcl_miss               vcl_fetch
                                                                               pass



                                                                               vcl_pass
                    pass
if (beresp.ttl <= 0s || beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
    set beresp.ttl = 120 s;
    return (hit_for_pass);
}
return (deliver);
resp.
                       pipe
                                                            vcl_pipe
                                                                                             error


                                                                                              vcl_error
         restart
                                                                                                     deliver
                              lookup                                              deliver
Request            vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                                  pass
                                                                                                     deliver
                                                                                  fetch
                                                                       vcl_miss               vcl_fetch
                                                                                  pass



                                                                                  vcl_pass
                       pass
return (deliver);
pipe
                                                         vcl_pipe
                                                                                          error


                                                                                           vcl_error
      restart
                                                                                                  deliver
                           lookup                                              deliver
Request         vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                               pass
                                                                                                  deliver
                                                                               fetch
                                                                    vcl_miss               vcl_fetch
                                                                               pass



                                                                               vcl_pass
                    pass
set obj.http.Content-Type = "text/html; charset=utf-8";
set obj.http.Retry-After = "5";
synthetic {"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} + obj.status + " " + obj.response + {"</title>
</head>
<body>
<h1>Error "} + obj.status + " " + obj.response + {"</h1>
<p>"} + obj.response + {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} + req.xid + {"</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
"};
return (deliver);
Varnish Workflow




http://www.flickr.com/photos/w4nd3rl0st/6604159789
lookup
Request   vcl_recv            vcl_hash   cached?                      vcl_deliver     Response

                                                                            deliver
                                                              fetch
                                                   vcl_miss           vcl_fetch
lookup                                  deliver
Request   vcl_recv            vcl_hash   cached?   vcl_hit             vcl_deliver   Response
pipe
                     vcl_pipe




Request   vcl_recv              Response
lookup
Request   vcl_recv            vcl_hash   cached?   vcl_hit               vcl_deliver     Response
                                                              pass
                                                                               deliver

                                                   vcl_miss              vcl_fetch
                                                              pass



                                                              vcl_pass
              pass
pipe
                                                         vcl_pipe
                                                                                          error


                                                                                           vcl_error
      restart
                                                                                                  deliver
                           lookup                                              deliver
Request         vcl_recv            vcl_hash   cached?              vcl_hit               vcl_deliver       Response
                                                                               pass
                                                                                                  deliver
                                                                               fetch
                                                                    vcl_miss               vcl_fetch
                                                                               pass



                                                                               vcl_pass
                    pass
VCL Recipes




              http://www.flickr.com/photos/christijohnstone/5474556299
backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

sub vcl_recv
{
    if ((req.request == "GET" || req.request == "HEAD") && req.url ~ ".
(png|gif|jpg|swf|css|js)$") {
        unset req.http.cookie;

        return(lookup);
    }
}

sub vcl_fetch
{
    if (req.url ~ ".(png|gif|jpg|swf|css|js)$") {
        remove beresp.http.set-cookie;

        set beresp.ttl = 2h;
    }
}
sub vcl_hit
{
    if (...) {
        if (obj.hits >= 10) {
            set obj.ttl = obj.ttl * 2;
        }
    }
}
backend app {
    .host = "192.168.0.1";
    .port = "8080";
}

backend images {
    .host = "192.168.0.2";
    .port = "8080";
}
sub vcl_recv
{
    set req.backend = app;

    if (req.url ~ ".(gif|jpg|swf|css|js)$") {
        set req.backend = images;
    }
}
sub vcl_deliver
{
    set resp.http.X-Cache = obj.hits+" "+req.backend;
}
sub vcl_recv {
    if (req.http.host ~ "^(?i)example.org" && req.http.X-
Forwarded-Proto !~ "(?i)https") {
         set req.http.x-Redir-Url = "https://example.org" +
req.url;

        error 750 req.http.x-Redir-Url;
    }
}

sub vcl_error {
    if (obj.status == 750) {
        set obj.http.Location = obj.response;
        set obj.status = 302;

        return (deliver);
    }
}
sub vcl_recv {
    if (req.http.Cookie) {
        set req.http.Cookie =
regsuball(req.http.Cookie,"(^|; ) *__utm.=[^;]+;? *",
"1");
        if (req.http.Cookie == "") {
            remove req.http.Cookie;
        }
    }
}
Saving the Request




 http://www.flickr.com/photos/lwr/5014290292
backend app {
    .host = "192.168.0.1";
    .port = "8080";
}

backend rescue {
    .host = "1.1.1.1";
    .port = "8080";
}
sub vcl_fetch
{
    if (beresp.status == 500) {
        return (restart);
    }
}

sub vcl_recv
{
    set req.backend = default;

    if (req.restarts > 0) {
        set req.backend = rescue;
    }
}
director balance round-robin
{
    { .backend = web1; }
    { .backend = web2; }
}

director balance random
{
    { .backend = web1; .weight = 2 }
    { .backend = web2; .weight = 1 }
}
director balance fallback
{
    { .backend = web1; }
    { .backend = web2; }
}

director balance client
{
    { .backend = web1; .weight = 2 }
    { .backend = web2; .weight = 1 }
}

director balance hash
{
    { .backend = web1; .weight = 2 }
    { .backend = web2; .weight = 1 }
}
stale-while-revalidate - rfc5861
sub vcl_fetch
{
    set beresp.grace = 30m;
}

sub vcl_recv
{
    set req.grace = 15s;
}
sub vcl_recv
{
    set req.grace = 15s;

    if (!req.backend.healthy) {
       set req.grace = 5m;
    }
}
probe health {
    .url = "/test_health";
    .expected_response = 200;
    .interval = 5s;
    .timeout = 1s;
    .window = 5;
    .threshold = 3;
}

backend default
{
    .host = "127.0.0.1";
    .port = "8080";
    .probe = health;
}
stale-if-error - rfc5861
sub vcl_fetch
{
    if (beresp.status == 500) {
        set beresp.saintmode = 10s;

        return (restart);
    }

    set beresp.grace = 30m;
}
Cache Invalidation




                     http://www.flickr.com/photos/r80o/5549288
sub vcl_recv
{
    if (req.request == "PURGE") {
        purge_url(req.url);
        error 200 "Purged";
    }
}
acl purge_acl {
    "localhost";
    "192.168.55.0/24";
}

sub vcl_recv
{
    if (req.request == "PURGE") {
        if (!client.ip ~ purge_acl) {
             error 405 "Not allowed";
        }

        purge_url(req.url);
        error 200 "Purged";
    }
}
varnishadm -S /etc/varnish/secret
  -T 127.0.0.1:6082 "ban.url .*"
ban req.http.host == "example.com"
     && req.http.url ~ ".png$"
Edge Side Includes
       ESI
cacheable for 10 minutes
                                                                          cacheable for 5 seconds

  Lorem	
  ipsum	
  dolor	
  sit	
  amet,	
  consectetur	
   Lorem	
  ipsum	
  dolor	
  sit	
  amet,	
  
adipiscing	
  elit.	
  In	
  vel	
  nulla	
  arcu,	
  vitae	
  cursus	
   consectetur	
  adipiscing	
  elit.	
  
      nunc.	
  Integer	
  semper	
  turpis	
  et	
  enim	
                   In	
  vel	
  nulla	
  arcu,	
  vitae	
  
 porCtor	
  iaculis.	
  Nulla	
  facilisi.	
  Lorem	
  ipsum	
                cursus	
  nunc.	
  Integer	
  
  dolor	
  sit	
  amet,	
  consectetur	
  adipiscing	
  elit.	
              semper	
  turpis	
  et	
  enim	
  
Mauris	
  vehicula	
  vesFbulum	
  dictum.	
  Aenean	
                       porCtor	
  iaculis.	
  Nulla	
  
         non	
  velit	
  tortor.	
  Nullam	
  adipiscing	
                facilisi.	
  Lorem	
  ipsum	
  dolor	
  
 malesuada	
  aliquam.	
  Mauris	
  dignissim,	
  urna	
                      sit	
  amet,	
  consectetur	
  
quis	
  iaculis	
  tempus,	
  justo	
  libero	
  porCtor	
  est,	
   adipiscing	
  elit.	
  Mauris	
  
  nec	
  eleifend	
  est	
  elit	
  vitae	
  ante.	
  Curabitur	
   vehicula	
  vesFbulum	
  dictum.	
  
  interdum	
  luctus	
  metus,	
  in	
  pulvinar	
  lectus	
                Aenean	
  non	
  velit	
  tortor.	
  
   rutrum	
  sit	
  amet.	
  Duis	
  gravida,	
  metus	
  in	
                  Nullam	
  adipiscing	
  
 dictum	
  eleifend,	
  dolor	
  risus	
  Fncidunt	
  ligula,	
   malesuada	
  aliquam.	
  Mauris	
  
    non	
  volutpat	
  nulla	
  sapien	
  in	
  elit.	
  Nulla	
          dignissim,	
  urna	
  quis	
  iaculis	
  
  rutrum	
  erat	
  id	
  neque	
  suscipit	
  eu	
  ultricies	
               tempus,	
  justo	
  libero	
  
    odio	
  sollicitudin.	
  Aliquam	
  a	
  mi	
  vel	
  eros	
           porCtor	
  est,	
  nec	
  eleifend	
  
    placerat	
  hendrerit.	
  Phasellus	
  porCtor,	
   est	
  elit	
  vitae	
  ante.	
  Curabitur	
  
 augue	
  sit	
  amet	
  vulputate	
  venenaFs,	
  dui	
  leo	
   interdum	
  luctus	
  metus.
  commodo	
  odio,	
  a	
  euismod	
  turpis	
  ligula	
  in	
  
                               elit.	
  
ESI… or Edge Side Includes

http://www.w3.org/TR/esi-lang
t ESI
    hou
Wit

                  Lorem	
  ipsum	
  dolor	
  sit	
  amet,	
  consectetur	
   Lorem	
  ipsum	
  dolor	
  sit	
  amet,	
  
                adipiscing	
  elit.	
  In	
  vel	
  nulla	
  arcu,	
  vitae	
  cursus	
   consectetur	
  adipiscing	
  elit.	
  
                      nunc.	
  Integer	
  semper	
  turpis	
  et	
  enim	
                   In	
  vel	
  nulla	
  arcu,	
  vitae	
  
                 porCtor	
  iaculis.	
  Nulla	
  facilisi.	
  Lorem	
  ipsum	
                cursus	
  nunc.	
  Integer	
  
                  dolor	
  sit	
  amet,	
  consectetur	
  adipiscing	
  elit.	
              semper	
  turpis	
  et	
  enim	
  
                Mauris	
  vehicula	
  vesFbulum	
  dictum.	
  Aenean	
                       porCtor	
  iaculis.	
  Nulla	
  
                         non	
  velit	
  tortor.	
  Nullam	
  adipiscing	
                facilisi.	
  Lorem	
  ipsum	
  dolor	
  
                 malesuada	
  aliquam.	
  Mauris	
  dignissim,	
  urna	
                      sit	
  amet,	
  consectetur	
  
                quis	
  iaculis	
  tempus,	
  justo	
  libero	
  porCtor	
  est,	
   adipiscing	
  elit.	
  Mauris	
  
                  nec	
  eleifend	
  est	
  elit	
  vitae	
  ante.	
  Curabitur	
   vehicula	
  vesFbulum	
  dictum.	
  
                  interdum	
  luctus	
  metus,	
  in	
  pulvinar	
  lectus	
                Aenean	
  non	
  velit	
  tortor.	
  
                   rutrum	
  sit	
  amet.	
  Duis	
  gravida,	
  metus	
  in	
                  Nullam	
  adipiscing	
  
                 dictum	
  eleifend,	
  dolor	
  risus	
  Fncidunt	
  ligula,	
   malesuada	
  aliquam.	
  Mauris	
  
                    non	
  volutpat	
  nulla	
  sapien	
  in	
  elit.	
  Nulla	
          dignissim,	
  urna	
  quis	
  iaculis	
  
                  rutrum	
  erat	
  id	
  neque	
  suscipit	
  eu	
  ultricies	
               tempus,	
  justo	
  libero	
  
                    odio	
  sollicitudin.	
  Aliquam	
  a	
  mi	
  vel	
  eros	
           porCtor	
  est,	
  nec	
  eleifend	
  
                    placerat	
  hendrerit.	
  Phasellus	
  porCtor,	
   est	
  elit	
  vitae	
  ante.	
  Curabitur	
  
                 augue	
  sit	
  amet	
  vulputate	
  venenaFs,	
  dui	
  leo	
   interdum	
  luctus	
  metus.
                  commodo	
  odio,	
  a	
  euismod	
  turpis	
  ligula	
  in	
  
                                               elit.	
  
ESI
W ith
                                              <esi:include src="..." />
              Lorem	
  ipsum	
  dolor	
  sit	
  amet,	
  consectetur	
  
            adipiscing	
  elit.	
  In	
  vel	
  nulla	
  arcu,	
  vitae	
  cursus	
  
                  nunc.	
  Integer	
  semper	
  turpis	
  et	
  enim	
  
             porCtor	
  iaculis.	
  Nulla	
  facilisi.	
  Lorem	
  ipsum	
  
              dolor	
  sit	
  amet,	
  consectetur	
  adipiscing	
  elit.	
  
            Mauris	
  vehicula	
  vesFbulum	
  dictum.	
  Aenean	
  
                     non	
  velit	
  tortor.	
  Nullam	
  adipiscing	
  
             malesuada	
  aliquam.	
  Mauris	
  dignissim,	
  urna	
  
            quis	
  iaculis	
  tempus,	
  justo	
  libero	
  porCtor	
  est,	
  
              nec	
  eleifend	
  est	
  elit	
  vitae	
  ante.	
  Curabitur	
  
              interdum	
  luctus	
  metus,	
  in	
  pulvinar	
  lectus	
  
               rutrum	
  sit	
  amet.	
  Duis	
  gravida,	
  metus	
  in	
  
             dictum	
  eleifend,	
  dolor	
  risus	
  Fncidunt	
  ligula,	
  
                non	
  volutpat	
  nulla	
  sapien	
  in	
  elit.	
  Nulla	
  
              rutrum	
  erat	
  id	
  neque	
  suscipit	
  eu	
  ultricies	
  
                odio	
  sollicitudin.	
  Aliquam	
  a	
  mi	
  vel	
  eros	
  
                placerat	
  hendrerit.	
  Phasellus	
  porCtor,	
  
             augue	
  sit	
  amet	
  vulputate	
  venenaFs,	
  dui	
  leo	
  
              commodo	
  odio,	
  a	
  euismod	
  turpis	
  ligula	
  in	
  
                                           elit.	
  
GET /foo HTTP/1.1                                       GET /foo HTTP/1.1                                       GET /foo HTTP/1.1
          Host: foo.org                                           Host: foo.org                                           Host: foo.org

                                                                                                                           HTTP/1.1 200 OK
                                                                                                                           C-C: s-maxage=600
                                                                                                                          Lorem	
       <esi:include	
  
                                                                                                                          ipsum	
      src="hNp.."	
  />
                                                                                                                           dolor	
  




                                                                                                                                                           Your PHP application
                                                                                                          Gateway Cache
                                                  Browser Cache
                                                                                                                          GET /bar HTTP/1.1
Browser




                                                                                                                          Host: foo.org


               HTTP/1.1 200 OK                                        HTTP/1.1 200 OK                                      HTTP/1.1 200 OK
                                                                                                                           C-C: s-maxage=5
             Lorem	
  ipsum	
   Lorem	
                             Lorem	
  ipsum	
   Lorem	
                             Lorem	
  ipsum	
  
            dolor	
  sit	
  amet,	
   ipsum	
                      dolor	
  sit	
  amet,	
   ipsum	
                           dolor
                                       dolor                                                  dolor



                                                                                                  GET /bar
                                                                                                  C-C: s-maxage=5

                                                                                                  Lorem

                                                                                                  GET /foo
                                                                                                  C-C: s-maxage=600

                                                                                                  Lor <esi:include />
GET /foo HTTP/1.1                                       GET /foo HTTP/1.1
          Host: foo.org                                           Host: foo.org




                                                                                                                          Your PHP application
                                                                                                          Gateway Cache
                                                  Browser Cache
Browser




               HTTP/1.1 200 OK                                        HTTP/1.1 200 OK

             Lorem	
  ipsum	
   Lorem	
                             Lorem	
  ipsum	
   Lorem	
  
            dolor	
  sit	
  amet,	
   ipsum	
                      dolor	
  sit	
  amet,	
   ipsum	
  
                                       dolor                                                  dolor



                                                                                                  GET /bar
                                                                                                  C-C: s-maxage=5

                                                                                                  Lorem

                                                                                                  GET /foo
                                                                                                  C-C: s-maxage=600
2 seconds later…                                                                                  Lor <esi:include />
GET /foo HTTP/1.1                                       GET /foo HTTP/1.1
          Host: foo.org                                           Host: foo.org




                                                                                                                                                Your PHP application
                                                                                                          Gateway Cache
                                                  Browser Cache
                                                                                                                          GET /bar HTTP/1.1
Browser




                                                                                                                          Host: foo.org


               HTTP/1.1 200 OK                                        HTTP/1.1 200 OK                                      HTTP/1.1 200 OK
                                                                                                                           C-C: s-maxage=5
             Lorem	
  ipsum	
   Lorem	
                             Lorem	
  ipsum	
   Lorem	
                             Lorem	
  ipsum	
  
            dolor	
  sit	
  amet,	
   ipsum	
                      dolor	
  sit	
  amet,	
   ipsum	
                           dolor
                                       dolor                                                  dolor



                                                                                                  GET /bar
                                                                                                  C-C: s-maxage=5

                                                                                                  Lorem

                                                                                                  GET /foo
                                                                                                  C-C: s-maxage=600
7 seconds later…                                                                                  Lor <esi:include />
Surrogate-Capability
       Surrogate-Control

http://www.w3.org/TR/edge-arch
Surrogate-Capability: abc="Surrogate/1.0 ESI/1.0"
Surrogate-Control: content="ESI/1.0"
sub vcl_recv
{
    set req.http.Surrogate-Capability = "abc=ESI/
1.0";
}

sub vcl_fetch
{
    if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
        unset beresp.http.Surrogate-Control;
        unset beresp.http.Cache-Control;
        set beresp.do_esi = true;
    }
}
http://www.flickr.com/photos/atoach/2118513722
Caching only works for “safe” HTTP methods
              (like GET & HEAD)
Never change the state of the server
       when serving a GET request

(we are talking about the application’s state of course,
                 you can log, cache, …)
Cache-Control: private
Pages with cookies
are not cached by default
Terminate SSL
64 bits
Thank You

More Related Content

What's hot

Making the Most of HTTP In Your Apps
Making the Most of HTTP In Your AppsMaking the Most of HTTP In Your Apps
Making the Most of HTTP In Your AppsBen Ramsey
 
IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."
IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."
IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."Dongwook Lee
 
DEF CON 27- ALBINOWAX - http desync attacks
DEF CON 27- ALBINOWAX - http desync attacksDEF CON 27- ALBINOWAX - http desync attacks
DEF CON 27- ALBINOWAX - http desync attacksFelipe Prado
 
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio LopesHTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio LopesCaelum
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedPort80 Software
 
[India Merge World Tour] Meru Networks
[India Merge World Tour] Meru Networks[India Merge World Tour] Meru Networks
[India Merge World Tour] Meru NetworksPerforce
 
HipHop VM: overclocking Symfony
HipHop VM: overclocking SymfonyHipHop VM: overclocking Symfony
HipHop VM: overclocking SymfonyVadim Borodavko
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptwebhostingguy
 
HTTP2:新的机遇与挑战
HTTP2:新的机遇与挑战HTTP2:新的机遇与挑战
HTTP2:新的机遇与挑战Jerry Qu
 
Bandwidth limiting howto
Bandwidth limiting howtoBandwidth limiting howto
Bandwidth limiting howtoDien Hien Tran
 
HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?Alessandro Nadalin
 
HAProxy scale out using open source
HAProxy scale out using open sourceHAProxy scale out using open source
HAProxy scale out using open sourceIngo Walz
 
Indy Tech Fest 2008 - ASP.NET MVC
Indy Tech Fest 2008 - ASP.NET MVCIndy Tech Fest 2008 - ASP.NET MVC
Indy Tech Fest 2008 - ASP.NET MVCaaronlerch
 
Integration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFSIntegration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFSChristophe Marchal
 
WebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUpWebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUphuguk
 
Async Tasks with Django Channels
Async Tasks with Django ChannelsAsync Tasks with Django Channels
Async Tasks with Django ChannelsAlbert O'Connor
 

What's hot (20)

Making the Most of HTTP In Your Apps
Making the Most of HTTP In Your AppsMaking the Most of HTTP In Your Apps
Making the Most of HTTP In Your Apps
 
IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."
IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."
IBM dwLive, "Internet & HTTP - 잃어버린 패킷을 찾아서..."
 
DEF CON 27- ALBINOWAX - http desync attacks
DEF CON 27- ALBINOWAX - http desync attacksDEF CON 27- ALBINOWAX - http desync attacks
DEF CON 27- ALBINOWAX - http desync attacks
 
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio LopesHTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
HTTP/2, SPDY e Otimizações Web - Front In Maceió 2014 - Sérgio Lopes
 
US07FFT-mod_ftp.ppt
US07FFT-mod_ftp.pptUS07FFT-mod_ftp.ppt
US07FFT-mod_ftp.ppt
 
Web Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting StartedWeb Server Technologies I: HTTP & Getting Started
Web Server Technologies I: HTTP & Getting Started
 
WP HTTP API
WP HTTP APIWP HTTP API
WP HTTP API
 
[India Merge World Tour] Meru Networks
[India Merge World Tour] Meru Networks[India Merge World Tour] Meru Networks
[India Merge World Tour] Meru Networks
 
HipHop VM: overclocking Symfony
HipHop VM: overclocking SymfonyHipHop VM: overclocking Symfony
HipHop VM: overclocking Symfony
 
Utosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.pptUtosc2007_Apache_Configuration.ppt
Utosc2007_Apache_Configuration.ppt
 
HTTP2:新的机遇与挑战
HTTP2:新的机遇与挑战HTTP2:新的机遇与挑战
HTTP2:新的机遇与挑战
 
Bandwidth limiting howto
Bandwidth limiting howtoBandwidth limiting howto
Bandwidth limiting howto
 
HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?HTTP colon slash slash: the end of the road?
HTTP colon slash slash: the end of the road?
 
HAProxy scale out using open source
HAProxy scale out using open sourceHAProxy scale out using open source
HAProxy scale out using open source
 
Indy Tech Fest 2008 - ASP.NET MVC
Indy Tech Fest 2008 - ASP.NET MVCIndy Tech Fest 2008 - ASP.NET MVC
Indy Tech Fest 2008 - ASP.NET MVC
 
Integration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFSIntegration with hdfs using WebDFS and NFS
Integration with hdfs using WebDFS and NFS
 
WebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUpWebHDFS at King - May 2014 Hadoop MeetUp
WebHDFS at King - May 2014 Hadoop MeetUp
 
Async Tasks with Django Channels
Async Tasks with Django ChannelsAsync Tasks with Django Channels
Async Tasks with Django Channels
 
Real-Time Django
Real-Time DjangoReal-Time Django
Real-Time Django
 
SPDY - or maybe HTTP2.0
SPDY - or maybe HTTP2.0SPDY - or maybe HTTP2.0
SPDY - or maybe HTTP2.0
 

Viewers also liked

Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Fabien Potencier
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010Fabien Potencier
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Fabien Potencier
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Fabien Potencier
 
Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Fabien Potencier
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010Fabien Potencier
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSarah El-Atm
 
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014Barel Barelon
 
symfony 1.1 goodness (Dutch PHP Conference 2008)
symfony 1.1 goodness (Dutch PHP Conference 2008)symfony 1.1 goodness (Dutch PHP Conference 2008)
symfony 1.1 goodness (Dutch PHP Conference 2008)Fabien Potencier
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 WorldFabien Potencier
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Fabien Potencier
 
Caching on the Edge with Symfony2
Caching on the Edge with Symfony2Caching on the Edge with Symfony2
Caching on the Edge with Symfony2Fabien Potencier
 

Viewers also liked (20)

Look beyond PHP
Look beyond PHPLook beyond PHP
Look beyond PHP
 
Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2Unit and Functional Testing with Symfony2
Unit and Functional Testing with Symfony2
 
Varnishes
VarnishesVarnishes
Varnishes
 
Dependency injection - phpday 2010
Dependency injection - phpday 2010Dependency injection - phpday 2010
Dependency injection - phpday 2010
 
Dependency injection-zendcon-2010
Dependency injection-zendcon-2010Dependency injection-zendcon-2010
Dependency injection-zendcon-2010
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
PHP 5.3 in practice
PHP 5.3 in practicePHP 5.3 in practice
PHP 5.3 in practice
 
varnish
varnishvarnish
varnish
 
Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3Design patterns revisited with PHP 5.3
Design patterns revisited with PHP 5.3
 
Paints and varnishes
Paints and varnishesPaints and varnishes
Paints and varnishes
 
The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010The state of Symfony2 - SymfonyDay 2010
The state of Symfony2 - SymfonyDay 2010
 
Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010Symfony2 - OSIDays 2010
Symfony2 - OSIDays 2010
 
Symfony2 Components - The Event Dispatcher
Symfony2 Components - The Event DispatcherSymfony2 Components - The Event Dispatcher
Symfony2 Components - The Event Dispatcher
 
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014Making Symofny shine with Varnish - SymfonyCon Madrid 2014
Making Symofny shine with Varnish - SymfonyCon Madrid 2014
 
symfony 1.1 goodness (Dutch PHP Conference 2008)
symfony 1.1 goodness (Dutch PHP Conference 2008)symfony 1.1 goodness (Dutch PHP Conference 2008)
symfony 1.1 goodness (Dutch PHP Conference 2008)
 
News of the Symfony2 World
News of the Symfony2 WorldNews of the Symfony2 World
News of the Symfony2 World
 
Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010Dependency Injection - ConFoo 2010
Dependency Injection - ConFoo 2010
 
Caching on the Edge with Symfony2
Caching on the Edge with Symfony2Caching on the Edge with Symfony2
Caching on the Edge with Symfony2
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 

Similar to Speed up websites with Varnish 3

ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse ProxyApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse ProxyJim Jagielski
 
CORS review
CORS reviewCORS review
CORS reviewEric Ahn
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1hussulinux
 
In a HTTP/2 World - DeccanRubyConf 2017
In a HTTP/2 World - DeccanRubyConf 2017In a HTTP/2 World - DeccanRubyConf 2017
In a HTTP/2 World - DeccanRubyConf 2017Douglas Vaz
 
REST in peace @ IPC 2012 in Mainz
REST in peace @ IPC 2012 in MainzREST in peace @ IPC 2012 in Mainz
REST in peace @ IPC 2012 in MainzAlessandro Nadalin
 
Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...
Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...
Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...Leonel Morgado
 
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0Cory Forsyth
 
HTTP and Your Angry Dog
HTTP and Your Angry DogHTTP and Your Angry Dog
HTTP and Your Angry DogRoss Tuck
 
Frontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumFrontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumPierre Spring
 
Interactive web. O rly?
Interactive web. O rly?Interactive web. O rly?
Interactive web. O rly?timbc
 
Introduction to HTTP - Hypertext Transfer Protocol
Introduction to HTTP - Hypertext Transfer ProtocolIntroduction to HTTP - Hypertext Transfer Protocol
Introduction to HTTP - Hypertext Transfer ProtocolSantiago Basulto
 
HTTP Caching For The Win - REST Fest 2013
HTTP Caching For The Win - REST Fest 2013HTTP Caching For The Win - REST Fest 2013
HTTP Caching For The Win - REST Fest 2013Phil Harvey
 
Speedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsSpeedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsPierre Spring
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011Alessandro Nadalin
 
How web crawlers work
How web crawlers workHow web crawlers work
How web crawlers workGabriel Genê
 

Similar to Speed up websites with Varnish 3 (20)

API Design Workshop
API Design WorkshopAPI Design Workshop
API Design Workshop
 
5-WebServers.ppt
5-WebServers.ppt5-WebServers.ppt
5-WebServers.ppt
 
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse ProxyApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
 
CORS review
CORS reviewCORS review
CORS review
 
PHP Training: Module 1
PHP Training: Module 1PHP Training: Module 1
PHP Training: Module 1
 
In a HTTP/2 World - DeccanRubyConf 2017
In a HTTP/2 World - DeccanRubyConf 2017In a HTTP/2 World - DeccanRubyConf 2017
In a HTTP/2 World - DeccanRubyConf 2017
 
REST in peace @ IPC 2012 in Mainz
REST in peace @ IPC 2012 in MainzREST in peace @ IPC 2012 in Mainz
REST in peace @ IPC 2012 in Mainz
 
Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...
Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...
Metodologias de Programação IV - Aula 4, Secção 1 - Suporte para cache no pro...
 
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
HTTP by Hand: Exploring HTTP/1.0, 1.1 and 2.0
 
Spider Course Day 1
Spider Course Day 1Spider Course Day 1
Spider Course Day 1
 
HTTP and Your Angry Dog
HTTP and Your Angry DogHTTP and Your Angry Dog
HTTP and Your Angry Dog
 
Frontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler ForumFrontend Performance - Web Entwickler Forum
Frontend Performance - Web Entwickler Forum
 
Interactive web. O rly?
Interactive web. O rly?Interactive web. O rly?
Interactive web. O rly?
 
Introduction to HTTP - Hypertext Transfer Protocol
Introduction to HTTP - Hypertext Transfer ProtocolIntroduction to HTTP - Hypertext Transfer Protocol
Introduction to HTTP - Hypertext Transfer Protocol
 
ExaProxy
ExaProxyExaProxy
ExaProxy
 
HTTP Caching For The Win - REST Fest 2013
HTTP Caching For The Win - REST Fest 2013HTTP Caching For The Win - REST Fest 2013
HTTP Caching For The Win - REST Fest 2013
 
Speedy App: Frontend Performance Considerations
Speedy App: Frontend Performance ConsiderationsSpeedy App: Frontend Performance Considerations
Speedy App: Frontend Performance Considerations
 
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011REST in ( a mobile ) peace @ WHYMCA 05-21-2011
REST in ( a mobile ) peace @ WHYMCA 05-21-2011
 
How web crawlers work
How web crawlers workHow web crawlers work
How web crawlers work
 
Rest
RestRest
Rest
 

More from Fabien Potencier

Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201Fabien Potencier
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Fabien Potencier
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Fabien Potencier
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Fabien Potencier
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Fabien Potencier
 
Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009Fabien Potencier
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPFabien Potencier
 
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)Fabien Potencier
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)Fabien Potencier
 

More from Fabien Potencier (15)

Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Dependency Injection IPC 201
Dependency Injection IPC 201Dependency Injection IPC 201
Dependency Injection IPC 201
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3Dependency Injection with PHP 5.3
Dependency Injection with PHP 5.3
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
 
Playing With PHP 5.3
Playing With PHP 5.3Playing With PHP 5.3
Playing With PHP 5.3
 
Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
 
Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009Symfony And Zend Framework Together 2009
Symfony And Zend Framework Together 2009
 
Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
symfony: Un Framework Open-Source pour les Entreprises (Solutions Linux 2008)
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 

Recently uploaded

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
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
 
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
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
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
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 

Recently uploaded (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
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
 
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
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
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
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 

Speed up websites with Varnish 3

  • 1. Varnish 3 The easy way to speed up your websites @fabpot fabien@symfony.com http://www.flickr.com/photos/laserstars/908946494
  • 2. Varnish is an HTTP accelerator http://www.flickr.com/photos/stuckincustoms/3232133635
  • 3. Varnish is a Caching Reverse Proxy http://www.flickr.com/photos/stuckincustoms/3232133635
  • 4. Kinds of caches http://www.flickr.com/photos/jnarin/2993803017
  • 5. Browser Browser Browser Browser Cache Browser Cache Browser Cache Within a Company On the server side Your PHP application
  • 6. Browser Browser Browser Browser Browser Browser Browser Cache Browser Cache Browser Cache Browser Cache Browser Cache Browser Cache Proxy Cache Proxy Cache Within a Company Within a Company On the server side Your PHP application
  • 7. Browser Browser Browser Browser Browser Browser Cache Browser Cache Browser Cache Browser Cache Browser Cache Proxy Cache Within a Company On the server side Reverse Proxy Cache Your PHP application
  • 8. HTTP and Caching http://www.flickr.com/photos/hdz/5623651313
  • 9. RFC 2616 – HTTP/1.1 http://www.ietf.org/rfc/rfc2616.txt http://tools.ietf.org/wg/httpbis/
  • 10. The Client sends a Request to the Server The Server sends back a Response to the Client A Client (browser, bot, WS, curl, …) A Server (Apache, nginx, …) The Request and the Response are HTTP messages
  • 11. GET / HTTP/1.1 Host: http.trainings.sensiolabs.com
  • 12. HTTP/1.1 200 OK Date: Wed, 15 Oct 2005 07:07:07 GMT Server: Apache Content-Length: 14 Content-Type: text/html Hello World!
  • 13. Caching in the HTTP Specification
  • 14.  p1: Messaging: Low-level message parsing and connection management  p2: Semantics: Methods, status codes and headers  p3: Payload: Dealing with content, message-specific headers  p4: Conditional Requests: e.g., If-Modified-Since  p5: Range Requests: Getting partial content  p6: Caching: Browser and intermediary caches  p7: Authentication: HTTP authentication framework
  • 17. The goal is to never generate the same response twice http://www.flickr.com/photos/donaldmacleod/3439612846
  • 19. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Some Cache Browser GET /foo HTTP/1.1 200 OK Cache-Control: s- maxage=10 Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Cache-­‐Control:  s-­‐maxage=10 Hello Hello
  • 20. Before expiration GET /foo HTTP/1.1 Your application is not called Host: foo.org Your PHP application Some Cache Browser GET /foo HTTP/1.1 200 OK Cache-Control: s- maxage=10 Hello HTTP/1.1 200 OK Hello
  • 21. After expiration GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Some Cache fresh Your PHP application Not Browser GET /foo HTTP/1.1 200 OK Cache-Control: s- maxage=10 Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Cache-Control: s-maxage=10 Hello Hello
  • 23. Last-Modified / If-Modified-Since Etag / If-None-Match
  • 24. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Some Cache Browser GET /foo HTTP/1.1 200 OK Last-Modified: Thu,   … Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Last-Modified: Thu,  … Last-Modified: Thu,  … Hello Hello
  • 25. If the resource has not changed GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org If-Modified-Since: Thu, Your PHP application Some Cache Browser GET /foo HTTP/1.1 200 OK Last-Modified: Thu,   … Hello HTTP/1.1 200 OK HTTP/1.1 304 Not Modified Last-Modified: Thu,  … Hello
  • 26. If the resource has changed GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org If-Modified-Since: Thu, Your PHP application Some Cache Browser GET /foo /foo GET HTTP/1.1 200 200 OK HTTP/1.1 OK Last-Modified: Sun,… Last-Modified: Thu,… Hello Hello HTTP/1.1 200 OK HTTP/1.1 200 OK Last-Modified: Sun,  … Last-Modified: Sun,  … Hello Hello
  • 27. You can combine HTTP headers the way you want Expiration wins over Validation
  • 28. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Some Cache Browser GET /foo HTTP/1.1 200 OK Etag: abcdef Cache-­‐Control:  max-­‐ age=10 … Hello HTTP/1.1 200 OK HTTP/1.1 200 OK ETag: abcdef ETag: abcdef Cache-­‐Control:  max-­‐age=10 Cache-­‐Control:  max-­‐age=10 Hello Hello
  • 29. Before expiration GET /foo HTTP/1.1 Host: foo.org Your application is not called Your PHP application Some Cache Browser GET /foo HTTP/1.1 200 OK Etag: abcdef Cache-­‐Control:  max-­‐ age=10 … Hello HTTP/1.1 200 OK ETag: abcdef Cache-­‐Control:  max-­‐age=10 Hello
  • 30. After expiration but resource still valid GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org If-None-Match: abcdef Your PHP application Some Cache Browser GET /foo HTTP/1.1 200 OK Etag: abcdef Cache-­‐Control:  max-­‐ age=10 … Hello HTTP/1.1 200 OK HTTP/1.1 304 Not Modified ETag: abcdef Cache-­‐Control:  max-­‐age=10 Cache-­‐Control:  max-­‐age=10 Hello
  • 32. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 Bob’s Cache … … Hello Hello Bob HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 C-C: max-age=600 Hello Hello Hello
  • 33. GET /foo HTTP/1.1 Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 Bob’s Cache … … Hello Hello Bob HTTP/1.1 200 OK C-C: max-age=600 Hello
  • 34. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK Browser Cache C-C: max-age=600 C-C: max-age=600 … … Hello Hello Alice HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: max-age=600 C-C: max-age=600 Hello Hello
  • 36. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: abcde Etag: abcde Bob’s Cache … … Hello Hello Bob HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: abcde Etag: abcde Etag: abcde Hello Hello Hello
  • 37. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org If-None-Match: ab If-None-Match: ab Your PHP application Reverse Proxy Cache GET /foo GET /foo HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: ab Etag: ab Bob’s Cache … … Hello Hello Bob HTTP/1.1 200 OK Etag: ab 304 Not Modified 304 Not Modified Hello
  • 38. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org If-None-Match: ab Your PHP application Reverse Proxy Cache GET /foo GET /foo Browser Cache HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: ab Etag: ab … … Hello Hello Alice HTTP/1.1 200 OK HTTP/1.1 200 OK Etag: ab Etag: ab 304 Not Modified Hello Hello
  • 39. VCL Varnish Configuration Language http://www.flickr.com/photos/akatayama/84707813
  • 40. backend default { .host = "127.0.0.1"; .port = "8080"; }
  • 41. pipe vcl_pipe error vcl_error restart deliver orkflow lookup deliver Request vcl_recv vcl_hash W cached? vcl_hit pass vcl_deliver Response deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 43. req. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 44. if (req.restarts == 0) { if (req.http.x-forwarded-for) { set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip; } else { set req.http.X-Forwarded-For = client.ip; } } if (req.request != "GET" && req.request != "HEAD" && req.request != "PUT" && req.request != "POST" && req.request != "TRACE" && req.request != "OPTIONS" && req.request != "DELETE") { return (pipe); } if (req.request != "GET" && req.request != "HEAD") { return (pass); } if (req.http.Authorization || req.http.Cookie) { return (pass); } return (lookup);
  • 45. req. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 46. hash_data(req.url); if (req.http.host) { hash_data(req.http.host); } else { hash_data(server.ip); } return (hash);
  • 47. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 48. req. obj. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 50. req. bereq. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 52. req. bereq. beresp. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 53. if (beresp.ttl <= 0s || beresp.http.Set-Cookie || beresp.http.Vary == "*") { set beresp.ttl = 120 s; return (hit_for_pass); } return (deliver);
  • 54. resp. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 56. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 57. set obj.http.Content-Type = "text/html; charset=utf-8"; set obj.http.Retry-After = "5"; synthetic {" <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>"} + obj.status + " " + obj.response + {"</title> </head> <body> <h1>Error "} + obj.status + " " + obj.response + {"</h1> <p>"} + obj.response + {"</p> <h3>Guru Meditation:</h3> <p>XID: "} + req.xid + {"</p> <hr> <p>Varnish cache server</p> </body> </html> "}; return (deliver);
  • 59. lookup Request vcl_recv vcl_hash cached? vcl_deliver Response deliver fetch vcl_miss vcl_fetch
  • 60. lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response
  • 61. pipe vcl_pipe Request vcl_recv Response
  • 62. lookup Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver vcl_miss vcl_fetch pass vcl_pass pass
  • 63. pipe vcl_pipe error vcl_error restart deliver lookup deliver Request vcl_recv vcl_hash cached? vcl_hit vcl_deliver Response pass deliver fetch vcl_miss vcl_fetch pass vcl_pass pass
  • 64. VCL Recipes http://www.flickr.com/photos/christijohnstone/5474556299
  • 65. backend default { .host = "127.0.0.1"; .port = "8080"; } sub vcl_recv { if ((req.request == "GET" || req.request == "HEAD") && req.url ~ ". (png|gif|jpg|swf|css|js)$") { unset req.http.cookie; return(lookup); } } sub vcl_fetch { if (req.url ~ ".(png|gif|jpg|swf|css|js)$") { remove beresp.http.set-cookie; set beresp.ttl = 2h; } }
  • 66. sub vcl_hit { if (...) { if (obj.hits >= 10) { set obj.ttl = obj.ttl * 2; } } }
  • 67. backend app { .host = "192.168.0.1"; .port = "8080"; } backend images { .host = "192.168.0.2"; .port = "8080"; }
  • 68. sub vcl_recv { set req.backend = app; if (req.url ~ ".(gif|jpg|swf|css|js)$") { set req.backend = images; } }
  • 69. sub vcl_deliver { set resp.http.X-Cache = obj.hits+" "+req.backend; }
  • 70. sub vcl_recv { if (req.http.host ~ "^(?i)example.org" && req.http.X- Forwarded-Proto !~ "(?i)https") { set req.http.x-Redir-Url = "https://example.org" + req.url; error 750 req.http.x-Redir-Url; } } sub vcl_error { if (obj.status == 750) { set obj.http.Location = obj.response; set obj.status = 302; return (deliver); } }
  • 71. sub vcl_recv { if (req.http.Cookie) { set req.http.Cookie = regsuball(req.http.Cookie,"(^|; ) *__utm.=[^;]+;? *", "1"); if (req.http.Cookie == "") { remove req.http.Cookie; } } }
  • 72. Saving the Request http://www.flickr.com/photos/lwr/5014290292
  • 73. backend app { .host = "192.168.0.1"; .port = "8080"; } backend rescue { .host = "1.1.1.1"; .port = "8080"; }
  • 74. sub vcl_fetch { if (beresp.status == 500) { return (restart); } } sub vcl_recv { set req.backend = default; if (req.restarts > 0) { set req.backend = rescue; } }
  • 75. director balance round-robin { { .backend = web1; } { .backend = web2; } } director balance random { { .backend = web1; .weight = 2 } { .backend = web2; .weight = 1 } }
  • 76. director balance fallback { { .backend = web1; } { .backend = web2; } } director balance client { { .backend = web1; .weight = 2 } { .backend = web2; .weight = 1 } } director balance hash { { .backend = web1; .weight = 2 } { .backend = web2; .weight = 1 } }
  • 78. sub vcl_fetch { set beresp.grace = 30m; } sub vcl_recv { set req.grace = 15s; }
  • 79. sub vcl_recv { set req.grace = 15s; if (!req.backend.healthy) { set req.grace = 5m; } }
  • 80. probe health { .url = "/test_health"; .expected_response = 200; .interval = 5s; .timeout = 1s; .window = 5; .threshold = 3; } backend default { .host = "127.0.0.1"; .port = "8080"; .probe = health; }
  • 82. sub vcl_fetch { if (beresp.status == 500) { set beresp.saintmode = 10s; return (restart); } set beresp.grace = 30m; }
  • 83. Cache Invalidation http://www.flickr.com/photos/r80o/5549288
  • 84. sub vcl_recv { if (req.request == "PURGE") { purge_url(req.url); error 200 "Purged"; } }
  • 85. acl purge_acl { "localhost"; "192.168.55.0/24"; } sub vcl_recv { if (req.request == "PURGE") { if (!client.ip ~ purge_acl) { error 405 "Not allowed"; } purge_url(req.url); error 200 "Purged"; } }
  • 86. varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 "ban.url .*"
  • 87. ban req.http.host == "example.com" && req.http.url ~ ".png$"
  • 89. cacheable for 10 minutes cacheable for 5 seconds Lorem  ipsum  dolor  sit  amet,  consectetur   Lorem  ipsum  dolor  sit  amet,   adipiscing  elit.  In  vel  nulla  arcu,  vitae  cursus   consectetur  adipiscing  elit.   nunc.  Integer  semper  turpis  et  enim   In  vel  nulla  arcu,  vitae   porCtor  iaculis.  Nulla  facilisi.  Lorem  ipsum   cursus  nunc.  Integer   dolor  sit  amet,  consectetur  adipiscing  elit.   semper  turpis  et  enim   Mauris  vehicula  vesFbulum  dictum.  Aenean   porCtor  iaculis.  Nulla   non  velit  tortor.  Nullam  adipiscing   facilisi.  Lorem  ipsum  dolor   malesuada  aliquam.  Mauris  dignissim,  urna   sit  amet,  consectetur   quis  iaculis  tempus,  justo  libero  porCtor  est,   adipiscing  elit.  Mauris   nec  eleifend  est  elit  vitae  ante.  Curabitur   vehicula  vesFbulum  dictum.   interdum  luctus  metus,  in  pulvinar  lectus   Aenean  non  velit  tortor.   rutrum  sit  amet.  Duis  gravida,  metus  in   Nullam  adipiscing   dictum  eleifend,  dolor  risus  Fncidunt  ligula,   malesuada  aliquam.  Mauris   non  volutpat  nulla  sapien  in  elit.  Nulla   dignissim,  urna  quis  iaculis   rutrum  erat  id  neque  suscipit  eu  ultricies   tempus,  justo  libero   odio  sollicitudin.  Aliquam  a  mi  vel  eros   porCtor  est,  nec  eleifend   placerat  hendrerit.  Phasellus  porCtor,   est  elit  vitae  ante.  Curabitur   augue  sit  amet  vulputate  venenaFs,  dui  leo   interdum  luctus  metus. commodo  odio,  a  euismod  turpis  ligula  in   elit.  
  • 90. ESI… or Edge Side Includes http://www.w3.org/TR/esi-lang
  • 91. t ESI hou Wit Lorem  ipsum  dolor  sit  amet,  consectetur   Lorem  ipsum  dolor  sit  amet,   adipiscing  elit.  In  vel  nulla  arcu,  vitae  cursus   consectetur  adipiscing  elit.   nunc.  Integer  semper  turpis  et  enim   In  vel  nulla  arcu,  vitae   porCtor  iaculis.  Nulla  facilisi.  Lorem  ipsum   cursus  nunc.  Integer   dolor  sit  amet,  consectetur  adipiscing  elit.   semper  turpis  et  enim   Mauris  vehicula  vesFbulum  dictum.  Aenean   porCtor  iaculis.  Nulla   non  velit  tortor.  Nullam  adipiscing   facilisi.  Lorem  ipsum  dolor   malesuada  aliquam.  Mauris  dignissim,  urna   sit  amet,  consectetur   quis  iaculis  tempus,  justo  libero  porCtor  est,   adipiscing  elit.  Mauris   nec  eleifend  est  elit  vitae  ante.  Curabitur   vehicula  vesFbulum  dictum.   interdum  luctus  metus,  in  pulvinar  lectus   Aenean  non  velit  tortor.   rutrum  sit  amet.  Duis  gravida,  metus  in   Nullam  adipiscing   dictum  eleifend,  dolor  risus  Fncidunt  ligula,   malesuada  aliquam.  Mauris   non  volutpat  nulla  sapien  in  elit.  Nulla   dignissim,  urna  quis  iaculis   rutrum  erat  id  neque  suscipit  eu  ultricies   tempus,  justo  libero   odio  sollicitudin.  Aliquam  a  mi  vel  eros   porCtor  est,  nec  eleifend   placerat  hendrerit.  Phasellus  porCtor,   est  elit  vitae  ante.  Curabitur   augue  sit  amet  vulputate  venenaFs,  dui  leo   interdum  luctus  metus. commodo  odio,  a  euismod  turpis  ligula  in   elit.  
  • 92. ESI W ith <esi:include src="..." /> Lorem  ipsum  dolor  sit  amet,  consectetur   adipiscing  elit.  In  vel  nulla  arcu,  vitae  cursus   nunc.  Integer  semper  turpis  et  enim   porCtor  iaculis.  Nulla  facilisi.  Lorem  ipsum   dolor  sit  amet,  consectetur  adipiscing  elit.   Mauris  vehicula  vesFbulum  dictum.  Aenean   non  velit  tortor.  Nullam  adipiscing   malesuada  aliquam.  Mauris  dignissim,  urna   quis  iaculis  tempus,  justo  libero  porCtor  est,   nec  eleifend  est  elit  vitae  ante.  Curabitur   interdum  luctus  metus,  in  pulvinar  lectus   rutrum  sit  amet.  Duis  gravida,  metus  in   dictum  eleifend,  dolor  risus  Fncidunt  ligula,   non  volutpat  nulla  sapien  in  elit.  Nulla   rutrum  erat  id  neque  suscipit  eu  ultricies   odio  sollicitudin.  Aliquam  a  mi  vel  eros   placerat  hendrerit.  Phasellus  porCtor,   augue  sit  amet  vulputate  venenaFs,  dui  leo   commodo  odio,  a  euismod  turpis  ligula  in   elit.  
  • 93. GET /foo HTTP/1.1 GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Host: foo.org HTTP/1.1 200 OK C-C: s-maxage=600 Lorem   <esi:include   ipsum   src="hNp.."  /> dolor   Your PHP application Gateway Cache Browser Cache GET /bar HTTP/1.1 Browser Host: foo.org HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: s-maxage=5 Lorem  ipsum   Lorem   Lorem  ipsum   Lorem   Lorem  ipsum   dolor  sit  amet,   ipsum   dolor  sit  amet,   ipsum   dolor dolor dolor GET /bar C-C: s-maxage=5 Lorem GET /foo C-C: s-maxage=600 Lor <esi:include />
  • 94. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Gateway Cache Browser Cache Browser HTTP/1.1 200 OK HTTP/1.1 200 OK Lorem  ipsum   Lorem   Lorem  ipsum   Lorem   dolor  sit  amet,   ipsum   dolor  sit  amet,   ipsum   dolor dolor GET /bar C-C: s-maxage=5 Lorem GET /foo C-C: s-maxage=600 2 seconds later… Lor <esi:include />
  • 95. GET /foo HTTP/1.1 GET /foo HTTP/1.1 Host: foo.org Host: foo.org Your PHP application Gateway Cache Browser Cache GET /bar HTTP/1.1 Browser Host: foo.org HTTP/1.1 200 OK HTTP/1.1 200 OK HTTP/1.1 200 OK C-C: s-maxage=5 Lorem  ipsum   Lorem   Lorem  ipsum   Lorem   Lorem  ipsum   dolor  sit  amet,   ipsum   dolor  sit  amet,   ipsum   dolor dolor dolor GET /bar C-C: s-maxage=5 Lorem GET /foo C-C: s-maxage=600 7 seconds later… Lor <esi:include />
  • 96. Surrogate-Capability Surrogate-Control http://www.w3.org/TR/edge-arch
  • 99. sub vcl_recv { set req.http.Surrogate-Capability = "abc=ESI/ 1.0"; } sub vcl_fetch { if (beresp.http.Surrogate-Control ~ "ESI/1.0") { unset beresp.http.Surrogate-Control; unset beresp.http.Cache-Control; set beresp.do_esi = true; } }
  • 101. Caching only works for “safe” HTTP methods (like GET & HEAD)
  • 102. Never change the state of the server when serving a GET request (we are talking about the application’s state of course, you can log, cache, …)
  • 104. Pages with cookies are not cached by default