From: phk Date: Mon, 6 Aug 2007 08:07:18 +0000 (+0000) Subject: Have the VCL compiler provide a hint about the worst case number of X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f2d1f460338e97b72306eed0039e3e8bdb832a8;p=varnish 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. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1803 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/vcl.h b/varnish-cache/include/vcl.h index 881e6e96..7574d3e9 100644 --- a/varnish-cache/include/vcl.h +++ b/varnish-cache/include/vcl.h @@ -26,6 +26,8 @@ struct VCL_conf { const char **srcname; const char **srcbody; + unsigned nhashcount; + void *priv; vcl_init_f *init_func; diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index 1cf063eb..6ad2cdad 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -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 != '=') { diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index e2826486..c38e2c62 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -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"); diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index 1ff47e0c..150a5824 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -83,6 +83,7 @@ struct tokenlist { struct proc *mprocs[N_METHODS]; unsigned recnt; + unsigned nhashcount; }; enum var_type { diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 4cb1f77b..3a0dd45f 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -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"); diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index d2af8ea8..4ee4caa4 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -142,6 +142,8 @@ puts $fo { unsigned magic; const char **srcname; const char **srcbody; + unsigned nhashcount; + void *priv; vcl_init_f *init_func;