]> err.no Git - varnish/commitdiff
Have the VCL compiler provide a hint about the worst case number of
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 6 Aug 2007 08:07:18 +0000 (08:07 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 6 Aug 2007 08:07:18 +0000 (08:07 +0000)
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.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1803 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/include/vcl.h
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_compile.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_fixed_token.c
varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl

index 881e6e96c4271a021495416d7efbd0e7c6940670..7574d3e938d5871bac0a9be79a1c824fc74142a5 100644 (file)
@@ -26,6 +26,8 @@ struct VCL_conf {
        const char      **srcname;
        const char      **srcbody;
 
+       unsigned        nhashcount;
+
         void            *priv;
 
         vcl_init_f      *init_func;
index 1cf063eb8efeaf1fa937a731f84a7b140b68bca4..6ad2cdadc07a31c712bf565e617ff46b66073262 100644 (file)
@@ -209,6 +209,12 @@ parse_set(struct tokenlist *tl)
                        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 != '=') {
index e28264864af042790d8d06a90b5945e3e952d6c3..c38e2c62dbcbeb05d45706987f5356b8edf694bc 100644 (file)
@@ -348,6 +348,7 @@ EmitStruct(const struct tokenlist *tl)
        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"); 
index 1ff47e0ca299268809be7395b7c8f69688e2bf85..150a58247f9f41ab1a0c2393764a37732d7ae045 100644 (file)
@@ -83,6 +83,7 @@ struct tokenlist {
        struct proc             *mprocs[N_METHODS];
 
        unsigned                recnt;
+       unsigned                nhashcount;
 };
 
 enum var_type {
index 4cb1f77bf79747e1cf2a1ddb43f5239debf01fd4..3a0dd45f8068498673c8f22d55b99465ddb0c442 100644 (file)
@@ -338,6 +338,8 @@ vcl_output_lang_h(struct vsb *sb)
        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");
index d2af8ea8feb9f73662630129b8d0f3a571331e5f..4ee4caa4fa16b8e571aab1ce94e9b4e3d81d7790 100755 (executable)
@@ -142,6 +142,8 @@ puts $fo {  unsigned        magic;
        const char      **srcname;
        const char      **srcbody;
 
+       unsigned        nhashcount;
+
         void            *priv;
 
         vcl_init_f      *init_func;