4.
What is Varnish?Official StatementWhat the hell it meansGraphs, oh my!

5.
Official Statement “Varnish is a web application accelerator. You install it in front of your web application and it will speed it up significantly.”5

6.
What The Hell? Tell me! • Varnish allow you to accelerate your website  By using memory and keeping in mind cookies, request headers and more… • It caches pages so that your web server can RELAX!  What about my apache, tomcat, nginx and (mongrel|thin| goliath….)  Generally caching by TTL + HTTP Headers (cookies too!) • A load banancer, proxy and more…  What? …. Yes, it can do that!6

7.
A General Use Case • CaringBridge Status Server  Getting a message to mobile users.  The system is down, or we want to be able to communicate a message to them about some subject… maybe a campaign.  The apps and mobile site rely on an API • Trouble in paradise? Few and far in between.  Let an API talk to a server…  A story on crashing and burning before varnish.7

13.
Documentation • Reference Manual  https://www.varnish-cache.org/docs/3.0/reference/index.html • Tutorial – more like a book version of the reference manual  https://www.varnish-cache.org/docs/3.0/tutorial/index.html • Knock yourselves out! There is a ton of documentation • Yes, this makes happy developers.  Documentation is very accurate, read carefully.  Focus heavily on VCL’s, that is generally what you need.  I’m attempting to show you some of how this works but you will require the documentation to assist you.13

22.
Directors • Directors allow you to talk to the backend servers • Directors are a glorified reverse proxy  Allows for certain types of load balancing  Allows for talking to a cluster “A director is a logical group of backend servers clustered together for redundancy. The basic role of the director is to let Varnish choose a backend server amongst several so if one is down another can be used.”22

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

29.
Using ESI • In vcl_fetch, you must set ESI to be on  set beresp.do_esi = true;  By default, ESI will still cache, so add an exclusion if you need it • if (req.url == “/show_username.php”) { return (pass); } • This is a good thing, you may want to cache user information to the right people (aka by cookie value) so that you don’t reload it on every request.  Varnish refuses to parse content for ESI if it does not look like XML • This is by default; so check varnishstat and varnishlog to ensure that it is functioning like normal.29

31.
Purging • The various ways of purging  varnishadm – command line utility • It’s the ole finger in the back of the throat  Sockets (port 6082) – everyone likes a good socket wrench • Sure, Ipecac is likely overkill.  HTTP – now that is the sexiness • A few headers, nothing forced.31

33.
Distributed Purging • Distributed Purging… like a sorority party.  Use a message queue (or gearman job server)  Have a worker that knows about the varnish servers  Submit the request to clear the cache in the asynchronously or synchronously depending on your use case. • Have enough workers to make this effective at purging the cache quickly.  This will make it far easier to scale; you can either store the servers in a config file, database or anything else you think is relevant.33

34.
Embedding C in VCL – you must be crazy • Before getting into VMOD; did you know you can embed C into the VCL for varnish? • Want to do something crazy fast or leverage a C library for pre or post processing? • I know… you’re thinking that’s useless..  On to the example; and a good one from the Varnish WIKI!34

36.
VMOD – Varnish Modules / Extensions • Taking VCL embedded C to the next level • Allows you to extend varnish and create new functions • Now, if you are writing modules for varnish you have a specialty use case!  Go read up on it!  https://www.varnish-cache.org/docs/trunk/reference/vmod.html36

41.
Logging • Many times people want to log the requests to a file  By default Varnish only stores these in shared memory.  Apache Style Logs • varnishncsa –D –a –w log.txt  This will run as a daemon to log all of your requests on a separate thread.41

43.
Cache Warmup • Need to warm up your cache before putting a sever in the queue or load test an environment?  varnishreplay –r log.txt • Replaying logs can allow you to do this. This is great for when you are going to be deploying code to check for performance issues.  Although… be careful so that you don’t POST data or create data on peoples accounts. Maybe cat the file and remove anything that executes on data.43

44.
Cache Hit Ratios? No Problem • How to see your cache hit ratios…  varnishstat • Want to parse them from XML so you can create a sexy administration panel?  varnishstat –x44