VarnishBOF!
What's this talk about?A basic intro to Varnish and reverse proxiesSome cool ESI stuffHow to setup, implement + configure Varnish/ESI in DrupalTeh Awesomeness of speed
Why Varnish?
Drupal performs…just…
How much faster?Drupal20 reqs/sec?Varnish200 reqs/sec?
When personalisation goes wrong
Dries logs in
Drupal creates a personalised pageLogged in as dries
The page gets cachedVarnish
When webchick hits the site
The page is fetched from the cacheVarnish
The personalisation is incorrectLogged in as dries
WTF?WTF?
No-cache headers can prevent thisVarnish
But now it's slow :-(
EdgeSideIncludes
ESI: Tales from the pastThe idea originated in SSISSI, but moved to the edgeESI is a W3C standardESI is a bunch of xml tags/attributes.Supported by:Varnish (partial support – no ESI variables)AkamaiSome Nginx support???
Dries is visiting the site
The page is requestedVarnishhttp://example.com/node/1
The page includes an ESI tag<esisrc=  "http://example.com/esi/user/0"  />
The proxy sends a second requesthttp://example.com/esi/user/0Varnishhttp://example.com/node/1
The ESI URL sends a HTML snip<div id="userinfo">  <a title="View &amp; edit your user profile">Logged in as dries</a>  <a href="/logout">Logout</a></div>
The ESI code is merged with the page
Proxy forwards the page onhttp://example.com/esi/user/0Varnishhttp://example.com/node/1
This doesn’t sound quicker
The Importance of TestsIt's important to measure the results(I'll come to measuring tools later!)The ESI snippets can be cached too
Cached ESIs
1st Page = 2 Requestshttp://example.com/esi/user/0Varnishhttp://example.com/node/1
2nd Page = 1 requestVarnishhttp://example.com/node/2
1 request for each new page10 pages = 11 requestsEach page is cachedThe ESI tag is cached
The next visitor gets the page for freeVarnishPage fetched from cachehttp://example.com/node/1
1st page = 1 request (for the ESI)http://example.com/esi/user/0VarnishPage fetched from cachehttp://example.com/node/1
Following pages all served from cacheVarnish
1 request for each new page10 pages = 11 requestsThe ESI tag is cachedEach page is cachedSubsequent requests have 1 request for the ESI tag20 pages = 12 requests (10 pages + 2 ESI tags)
Fast enough yet?Warm the cache
A modern infrastructureVarnishHA ProxyTehIntertubesService webheadadmin/cron/emails/??
Spidering the siteVarnishHA ProxyTehIntertubesLink-checker /spider app.Service webheadadmin/cron/emails/??
Dries is back for more
Each user generates 1 requesthttp://example.com/esi/user/0VarnishPage fetched from cachehttp://example.com/node/1
5 users, 40 pages5 backend requests!
Theory Over
Basics Varnish+Drupal
Installing Varnishsudo apt-get install varnishsudo yum install varnishEdit /etc/default/varnishEdit /etc/varnish/default.vclUsual config:Varnish listens on port 80Apache listens on port 8080 (or any available port)SSL is more complex – sometimes Pound is used for SSL decryption
VCLs are awesome!Varnish configuration is controlled by VCL: Varnish Configuration Language.Documented athttp://www.varnish-cache.org/trac/wiki/VCLDrupal VCL examples can be found in:Mercury (Amazon AMI)ESI moduleYou can write C code in VCLs. Oh my.
Keeping the cache currentVarnish admin portVarnish
Varnish Management PortThe Varnish admin port uses a plain-text protocol to command VarnishTest by:telnet localhost 6093List commands by typing helpPurge cached pages: url.purge <regexp>E.g. url.purge .*The Varnish module provides an API.
Use with caution!The default behaviour of the Varnish module is toclear the entire cachewhen you edit a node.
Enter…the Expires moduleCame from the Boost moduleClears specific cache pages – not the entire cacheSupports path-alias URLs as well as node/1 paths.Provides hook_expire_cache_alterto add URLs (e.g. nodes displayed in a page-view)Supports other cache modules, not just Varnish.
I can haz ESI?The ESI module provides block integration
Configuring ESIDownload the moduleConfigure the blocks to serve via ESI, and their TTLModify the Varnish VCL (the ESI module comes with example VCLs to useComing soon:D7Panels integration
BenchmarkingSome tools:J-meterab (apache-benchmark)SeigeApproaches:Hammer your URL(s)ab –n 100 –c5 http://example.com/Replay your log files
Pitfalls awaitVCLs are complexPer-user cache rules are even scarier!Varnish may be slowerRisk exposing private data
AlternativesBoost moduleNo need to install a new service on the serverStatic file cacheAdvanced cache moduleAuthcache moduleOther proxies:SquidNginxAkamai?
Summary
How hard?
VarnishVarnish moduleExpire moduleESI moduleTeh Awesomeness
Thanks!Marcus Deglose: marcus@deglos.comt: @manarthirc: manarth
Picture creditsThanks to these CC-licencedflickr usersMac Book Pro - http://www.flickr.com/photos/wicho/F1 car       - http://www.flickr.com/photos/w3i_yu/Banger car   - http://www.flickr.com/photos/photoplodDries        - http://www.flickr.com/photos/borisDries+laptop - http://www.flickr.com/photos/azugaldiaWebchick     - http://www.flickr.com/photos/mortendkWebchick     - http://www.flickr.com/photos/pureginFire         - http://www.flickr.com/photos/benwattsHourglass    - http://www.flickr.com/photos/opendemocracyStopwatch    - http://www.flickr.com/photos/purplemattfish

Varnish bof

Editor's Notes

  • #3 - Old hands: feel free to switch off for a while- New to Varnish? Welcome along
  • #4 You&apos;ve heard that varnish is *quicker* - so how is it quicker?
  • #5 - So what happens when you make a request?
  • #7 &gt; Pic of absurd personalisation
  • #13 What if it&apos;s *really* private info?This *does* happen!
  • #16 - Add EGGTIMER pic
  • #20 Page is requested,Gets a response
  • #21 - Add a pic of a page with an ESI TAG
  • #22 - Requests the ESI URL
  • #26 - More requests makes it slower!
  • #27 This shows how important *measurements* areI&apos;ll talk about measurements laterESIs can be cached
  • #36 - Warm the cache