talk. • Me – Sr. Web Architect Manager at NOOK Developer – Prior MNPHP Organizer – Open Source Contributor – Where you can find me: • Twitter: mwillbanks G+: Mike Willbanks • IRC (freenode): mwillbanks Blog: http://blog.digitalstruct.com • GitHub: https://github.com/mwillbanks
– -b address[:port] backend requests – -T address[:port] administration http – -s type[,options] storage type (malloc, file, persistence) – -P /path/to/file PID file – Many others; these are generally the most important. Generally the defaults will do with just modification of the default VCL (more on it later).
is Processed Separately & Independently – States are Isolated but are Related – Return statements exit one state and start another – VCL defaults are ALWAYS appended below your own VCL • VCL can be complex, but… – Two main subroutines; vcl_recv and vcl_fetch – Common actions: pass, hit_for_pass, lookup, pipe, deliver – Common variables: req, beresp and obj – More subroutines, functions and complexity can arise dependent on condition.
loaded, VMOD init) vcl_recv Beginning of request, req is in scope vcl_pipe Client & backend data passed unaltered vcl_pass Request goes to backend and not cached vcl_hash Creates cache hash, call hash_data for custom hashes vcl_hit Called when hash found in cache vcl_miss Called when hash not found in cache vcl_fetch Called to fetch data from backend vcl_deliver Called prior to delivery of response (excluding pipe) vcl_error Called when an error occurs vcl_fini Shutdown routine (VCL unload, VMOD cleanup)
to the hash input regsub(string, regex, sub) Substitution on first occurrence regsuball(string, regex, sub) Substitution on all occurrences ban(expression) Ban all items that match expression ban(regex) Ban all items that match regular expression
on random and weight. Client Picks based on client identity. Hash Picks based on hash value. Round Robin Goes in order and starts over DNS Picks based on incoming DNS host, random OR round robin. Fallback Picks the first “healthy” server.
markup language much like SSI (server side includes) to include fragments (or dynamic content for that matter). • Think of it as replacing regions inside of a page as if you were using XHR (AJAX) but single threaded. • Three Statements can be utilized. – esi:include – Include a page – esi:remove – Remove content – <!-- esi --> - ESI disabled, execute normally
be on – set beresp.do_esi = true; – Varnish refuses to parse content for ESI if it does not look like XML • This is by default; so check varnishstat and varnishlog to ensure that it is functioning like normal.
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!