When high performance on a web application is a hard requirement Varnish can be of rescue. But does it’s name, the high-performance HTTP accelerator, really bring what you expect? What are the caveats, pitfalls and problems you introduce when developing your application when the released version is only able to run when there is a Varnish in front? This session will give you some answers, tips and tricks to aid in application design, development with PHP and solutions when there is no Varnish in front of your application.
1. Varnish, the high performance valhalla? JEROEN VAN DIJK 29 JANUARY 2011
2. ABOUT ME Jeroen van Dijk CTO @ Enrise Email: jeroen@enrise.com @neorey on twitter Infected by open source…
3. WHAT IS VARNISH? (1) HTTP Accelerator Caching reverse proxy Load balancer Fail over system NOT a webserver!
4. WHAT IS VARNISH? (2) Originally built for a Norwegian newspaper > 545K new hostnames in December 2010 Netcraft monthly survey Known users Wikileaks Facebook Twitter Massive growth in usage
5. WHAT IS VARNISH? (3) Designed for 64 bit architecture Highly scalable Varnish in front of other Varnish(es) Perfect browser cache solution Prevent hard refresh calls Scaling limits currently unknown
14. VARNISH CONFIGURATION LANGUAGE(1) 9 subroutines (vcl_recv, vcl_hash, etc…) Backend(s) Access Control Lists Directors (random, round-robin) Custom subroutines Inline C Compiled to C when run
15. VARNISH CONFIGURATION LANGUAGE(2) if (req.request == "GET" && req.url ~ "(gif|jpg|jpeg|bmp|png|ico)$") { unset req.http.cookie; set req.grace = 1m; return(lookup); } Cache images in vcl_recv
16. VARNISH CONFIGURATION LANGUAGE(3) if (req.http.cookie) { set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", ""); if (req.http.cookie ~ "^ *$") { remove req.http.cookie; } } Remove Google Analytics in vcl_recv
23. VARNISHING WORDPRESS (4) # Drop any cookies sent to WordPress. sub vcl_recv { unset req.http.cookie; } # Drop any cookies WordPress tries to send back sub vcl_fetch { unset beresp.http.set-cookie; } Kill those cookies!
30. VARNISHLOG Log misses varnishlog –i TxURL Log hits varnishlog –o VCL_Call hit | grep RxURL This is a live log, not reading from file
31. EDGE SIDE INCLUDES (1) Markup language Co-authored by Akamai, IBM, Oracle & more Extensive features Varnish implements only one! <esi:include src=“uri” /> Very powerful for content assembly
32. EDGE SIDE INCLUDES (2) if … else <esi:choose><esi:when> … <esi:otherwise> Variables <esi:assign> and <esi:vars> Examples? http://esi-examples.akamai.com/
33. EDGE SIDE INCLUDES (3) if (req.url ~ "^/url/to/esi/snippets") { unset beresp.http.set-cookie; } ## enable esi on header from backend if (beresp.http.enable-esi == "1") { esi; unset beresp.http.enable-esi; } VCL config for ESI
37. CASE AUTOTRACK.NL (2) > 40 million pageviews a month >500k search requests between 8-10pm Powered by Varnish Zend Server Solr Oracle Built with 5 developers using Zend Framework 2 developers working on frontend logic
39. CASE AUTOTRACK.NL (4) Developing without Varnish ESI tags are not parsed Incorrect user interface Varnish is POSIX only
40. CASE AUTOTRACK.NL (5) Custom ZF view helper, called by $this->esi(‘uri’) protected static $_headerSent = false; public function esi($uri) { if(false === self::$_headerSent) { $front = Zend_Controller_Front::getInstance(); $response = $front->getResponse(); $response->setHeader('enable-esi', 1); self::$_headerSent = true; } return ‘<esi:include src="' . $uri . '"/>’; }
41. CASE AUTOTRACK.NL (6) Custom ZF controller plugin to the rescue Replace body content on dispatchLoopShutdown Cache the snippets like Varnish would do Respect Cache-Control TTL Functional testing of site during development