r4949 - in trunk/varnish-cache/doc/sphinx: reference tutorial

perbu at varnish-cache.org perbu at varnish-cache.org
Sat Jun 12 10:26:18 CEST 2010


Author: perbu
Date: 2010-06-12 10:26:18 +0200 (Sat, 12 Jun 2010)
New Revision: 4949

Added:
   trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst
Modified:
   trunk/varnish-cache/doc/sphinx/reference/vcl.rst
   trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst
   trunk/varnish-cache/doc/sphinx/tutorial/index.rst
   trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst
Log:
advanced topics pointed out + some minor fixes

Modified: trunk/varnish-cache/doc/sphinx/reference/vcl.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/reference/vcl.rst	2010-06-11 09:07:34 UTC (rev 4948)
+++ trunk/varnish-cache/doc/sphinx/reference/vcl.rst	2010-06-12 08:26:18 UTC (rev 4949)
@@ -1,3 +1,5 @@
+.. _reference-vcl:
+
 ===
 VCL
 ===

Added: trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst	                        (rev 0)
+++ trunk/varnish-cache/doc/sphinx/tutorial/advanced_topics.rst	2010-06-12 08:26:18 UTC (rev 4949)
@@ -0,0 +1,63 @@
+.. _tutorial-advanced_topics:
+
+Advanced topics
+---------------
+
+This tutorial has covered the basics in Varnish. If you read through
+it all you should now have the skills to run Varnish.
+
+Here is a short overview of topics that we haven't covered in the tutorial. 
+
+More VCL
+~~~~~~~~
+
+VCL is a bit more complex then what we've covered so far. There are a
+few more subroutines available and there a few actions that we haven't
+discussed. For a complete(ish) guide to VCL have a look at the VCL man
+page - `ref`:reference-vcl.
+
+Using Inline C to extend Varnish
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+You can use *inline C* to extend Varnish. Please note that you can
+seriously mess up Varnish this way. The C code runs within the Varnish
+Cache process so if your code generates a segfault the cache will crash.
+
+One of the first uses I saw of Inline C was logging to syslog.::
+
+	# The include statements must be outside the subroutines.
+	C{
+		#include <syslog.h>
+        }C
+	
+        sub vcl_something {
+                C{
+		        syslog(LOG_INFO, "Something happened at VCL line XX.");
+	        }C
+        }
+
+
+Edge Side Includes
+~~~~~~~~~~~~~~~~~~
+
+Varnish can cache create web pages by putting different pages
+together. These *fragments* can have individual cache policies. If you
+have a web site with a list showing the 5 most popular articles on
+your site this list can probably be cached as a fragment and included
+in all the other pages. Used properly it can dramatically increase
+your hitrate and reduce the load on your servers. ESI looks like this::
+
+  <HTML>
+  <BODY>
+  The time is: <esi:include src="/cgi-bin/date.cgi"/>
+  at this very moment.
+  </BODY>
+  </HTML>
+
+ESI is processed in vcl_fetch by using the *esi* keyword.::
+
+  sub vcl_fetch {
+      if (req.url == "/test.html") {
+	  esi;  /* Do ESI processing */
+      }
+  }

Modified: trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst	2010-06-11 09:07:34 UTC (rev 4948)
+++ trunk/varnish-cache/doc/sphinx/tutorial/increasing_your_hitrate.rst	2010-06-12 08:26:18 UTC (rev 4949)
@@ -116,6 +116,22 @@
 
   varnishlog -i TxHeader -I ^Age
 
+Overriding the time-to-live (ttl)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Sometimes your backend will misbehave. It might, depending on your
+setup, be easier to override the ttl in Varnish then to fix your
+somewhat cumbersome backend. 
+
+You need VCL to identify the objects you want and then you set the
+beresp.ttl to whatever you want.::
+
+  sub vcl_fetch {
+      if (req.url ~ "^/legacy_broken_cms/") {
+          set beresp.ttl = 5d;
+      }
+  }
+
 Cookies
 ~~~~~~~
 
@@ -304,7 +320,7 @@
 		  if (!client.ip ~ purge) {
 			  error 405 "Not allowed.";
 		  }
-		  lookup;
+		  return (lookup);
 	  }
   }
   
@@ -324,6 +340,11 @@
 	  }
   }
 
+As you can see we have used to new VCL subroutines, vcl_hit and
+vcl_miss. When we call lookup Varnish will try to lookup the object in
+its cache. It will either hit an object or miss it and so the
+corresponding subroutine is called. In vcl_hit the object that is
+stored in cache is available and we can set the TTL.
 
 So for vg.no to invalidate their front page they would call out to
 varnish like this:::

Modified: trunk/varnish-cache/doc/sphinx/tutorial/index.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/tutorial/index.rst	2010-06-11 09:07:34 UTC (rev 4948)
+++ trunk/varnish-cache/doc/sphinx/tutorial/index.rst	2010-06-12 08:26:18 UTC (rev 4949)
@@ -15,7 +15,7 @@
 We assume you have a web server and a web application up and running
 and that you want to accelerate this application with Varnish.
 
-Furthermore we assume you have read the :ref:`Installation` and that
+Furthermore we assume you have read the :ref:`install-index` and that
 it is installed with the default configuration.
 
 
@@ -31,6 +31,7 @@
         increasing_your_hitrate.rst
 	advanced_backend_servers.rst
         handling_misbehaving_servers.rst
+        advanced_topics.rst
 	troubleshooting.rst
 
 .. todo::

Modified: trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst
===================================================================
--- trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst	2010-06-11 09:07:34 UTC (rev 4948)
+++ trunk/varnish-cache/doc/sphinx/tutorial/vcl.rst	2010-06-12 08:26:18 UTC (rev 4949)
@@ -32,9 +32,11 @@
 received and parsed.  Its purpose is to decide whether or not to serve
 the request, how to do it, and, if applicable, which backend to use.
 
-In vcl_recv you can also alter the request, dropping cookies, rewrite
-headers.
+In vcl_recv you can also alter the request. Typically you can alter
+the cookies and add and remove request headers.
 
+Note that in vcl_recv only the request object, req is availble.
+
 vcl_fetch
 ~~~~~~~~~
 
@@ -43,6 +45,11 @@
 trigger ESI processing, try alternate backend servers in case the
 request failed.
 
+In vcl_fetch you still have the request object, req, available. There
+is also a *backend response*, beresp. beresp will contain the HTTP
+headers from the backend.
+
+
 actions
 ~~~~~~~
 




More information about the varnish-commit mailing list