r1803 - in trunk/varnish-cache: include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Mon Aug 6 10:07:18 CEST 2007


Author: phk
Date: 2007-08-06 10:07:18 +0200 (Mon, 06 Aug 2007)
New Revision: 1803

Modified:
   trunk/varnish-cache/include/vcl.h
   trunk/varnish-cache/lib/libvcl/vcc_action.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
Log:
Have the VCL compiler provide a hint about the worst case number of
operations on the req.hash variable.

It is only a hint, because it merely counts how many times the parser
saw something being added to the req.hash variable.  If the operation
was in a subroutine which was called multiple times, the hint will not
reflect the number of actual operations.

For now we will deal with that at runtime, at the expense of a
failed transaction every time we run short.  If this becomes an issue,
an extensive topological analysis of the VCL program can give us
a definitive count.



Modified: trunk/varnish-cache/include/vcl.h
===================================================================
--- trunk/varnish-cache/include/vcl.h	2007-08-05 21:06:41 UTC (rev 1802)
+++ trunk/varnish-cache/include/vcl.h	2007-08-06 08:07:18 UTC (rev 1803)
@@ -26,6 +26,8 @@
 	const char	**srcname;
 	const char	**srcbody;
 
+	unsigned	nhashcount;
+
         void            *priv;
 
         vcl_init_f      *init_func;

Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c	2007-08-05 21:06:41 UTC (rev 1802)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c	2007-08-06 08:07:18 UTC (rev 1803)
@@ -209,6 +209,12 @@
 			return;
 		}
 		Fb(tl, 0, ");\n");
+		/*
+		 * We count the number of operations on the req.hash
+		 * variable, so that varnishd can preallocate the worst case
+		 * number of slots for composing the hash string.
+		 */
+		tl->nhashcount++;
 		break;
 	case STRING:
 		if (tl->t->tok != '=') {

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2007-08-05 21:06:41 UTC (rev 1802)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2007-08-06 08:07:18 UTC (rev 1803)
@@ -348,6 +348,7 @@
 	Fc(tl, 0, "\t.nsrc = %u,\n", tl->nsources);
 	Fc(tl, 0, "\t.srcname = srcname,\n");
 	Fc(tl, 0, "\t.srcbody = srcbody,\n");
+	Fc(tl, 0, "\t.nhashcount = %u,\n", tl->nhashcount);
 #define VCL_RET_MAC(l,u,b,n)
 #define VCL_MET_MAC(l,u,b) \
 	Fc(tl, 0, "\t." #l "_func = VGC_function_vcl_" #l ",\n"); 

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-08-05 21:06:41 UTC (rev 1802)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-08-06 08:07:18 UTC (rev 1803)
@@ -83,6 +83,7 @@
 	struct proc		*mprocs[N_METHODS];
 
 	unsigned		recnt;
+	unsigned		nhashcount;
 };
 
 enum var_type {

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2007-08-05 21:06:41 UTC (rev 1802)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2007-08-06 08:07:18 UTC (rev 1803)
@@ -338,6 +338,8 @@
 	vsb_cat(sb, "	const char	**srcname;\n");
 	vsb_cat(sb, "	const char	**srcbody;\n");
 	vsb_cat(sb, "\n");
+	vsb_cat(sb, "	unsigned	nhashcount;\n");
+	vsb_cat(sb, "\n");
 	vsb_cat(sb, "        void            *priv;\n");
 	vsb_cat(sb, "\n");
 	vsb_cat(sb, "        vcl_init_f      *init_func;\n");

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2007-08-05 21:06:41 UTC (rev 1802)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2007-08-06 08:07:18 UTC (rev 1803)
@@ -142,6 +142,8 @@
 	const char	**srcname;
 	const char	**srcbody;
 
+	unsigned	nhashcount;
+
         void            *priv;
 
         vcl_init_f      *init_func;




More information about the varnish-commit mailing list