]> err.no Git - varnish/commitdiff
Add obj.hits VRT variable which counts how many *previous* hits
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 7 Sep 2008 17:31:13 +0000 (17:31 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 7 Sep 2008 17:31:13 +0000 (17:31 +0000)
this object has seen.

Idea for prefetching being used as workaround for #310

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

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_hash.c
varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/bin/varnishtest/tests/c00005.vtc
varnish-cache/bin/varnishtest/tests/v00013.vtc [new file with mode: 0644]
varnish-cache/include/vrt_obj.h
varnish-cache/lib/libvcl/vcc_gen_obj.tcl
varnish-cache/lib/libvcl/vcc_obj.c

index fa5ef529d29b1d8ddb9d92846ee186c65d51fffe..de1e19b24054cc4fc8fe45a57b70a4a9c8a6d8a4 100644 (file)
@@ -285,6 +285,8 @@ struct object {
        /* Prefetch */
        struct object           *parent;
        struct object           *child;
+
+       int                     hits;
 };
 
 struct objhead {
index f84cb4cd1e4851a2dc91c4c09e13c601b41c20d3..9f10202495a9c179a3f91fe0dc8a9cbc2073fe8d 100644 (file)
@@ -58,6 +58,7 @@
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
+#include <limits.h>
 #include <sys/types.h>
 #include <fcntl.h>
 
@@ -253,6 +254,8 @@ HSH_Lookup(struct sess *sp)
        if (o != NULL) {
                /* We found an object we like */
                o->refcnt++;
+               if (o->hits < INT_MAX)
+                       o->hits++;
                UNLOCK(&oh->mtx);
                if (params->log_hash)
                        WSP(sp, SLT_Hash, "%s", oh->hash);
index e373886386781ee4af3dbc1945c04986d88104b0..7c05549fea999126b8a9ff43f88bd89acb6efc93 100644 (file)
@@ -552,6 +552,15 @@ VRT_r_now(const struct sess *sp)
        return (TIM_real());
 }
 
+int
+VRT_r_obj_hits(const struct sess *sp)
+{
+
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+       CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);       /* XXX */
+       return (sp->obj->hits);
+}
+
 double
 VRT_r_obj_lastuse(const struct sess *sp)
 {
index 98ed37379ce1f645cad4957db8eb847bea40052c..f55d1904c00c45b60684055da153930893a6bfd4 100644 (file)
@@ -11,7 +11,7 @@ server s1 {
        txresp -body "2222\n"
 } -start
 
-varnish v1 -vcl+backend {
+varnish v1 -arg "-p vcl_trace=on" -vcl+backend {
        acl acl1 {
                "localhost";
        }
diff --git a/varnish-cache/bin/varnishtest/tests/v00013.vtc b/varnish-cache/bin/varnishtest/tests/v00013.vtc
new file mode 100644 (file)
index 0000000..322df74
--- /dev/null
@@ -0,0 +1,42 @@
+# $Id$
+
+test "Check obj.hits"
+
+server s1 {
+       rxreq
+       expect req.url == "/"
+       txresp -body "slash"
+       rxreq
+       expect req.url == "/foo"
+       txresp -body "foo"
+} -start
+
+varnish v1 -vcl+backend {
+
+       sub vcl_deliver {
+               set resp.http.foo = obj.hits;
+       }
+} -start
+
+client c1 {
+       txreq
+       rxresp
+       expect resp.status == 200
+       expect resp.http.foo == 0
+
+       txreq
+       rxresp
+       expect resp.status == 200
+       expect resp.http.foo == 1
+
+       txreq -url /foo
+       rxresp
+       expect resp.status == 200
+       expect resp.http.foo == 0
+
+       txreq
+       rxresp
+       expect resp.status == 200
+       expect resp.http.foo == 2
+} -run 
+
index 35f1f80421b8e24aa5c2c800d6ea874ee7967e26..6d7e691a601c42ec3a53da8b54c52c4f51a7aca5 100644 (file)
@@ -34,6 +34,7 @@ int VRT_r_obj_status(const struct sess *);
 void VRT_l_obj_status(const struct sess *, int);
 const char * VRT_r_obj_response(const struct sess *);
 void VRT_l_obj_response(const struct sess *, const char *, ...);
+int VRT_r_obj_hits(const struct sess *);
 unsigned VRT_r_obj_cacheable(const struct sess *);
 void VRT_l_obj_cacheable(const struct sess *, unsigned);
 double VRT_r_obj_ttl(const struct sess *);
index e26d3fa26aa21add35c337c5442822acd33aa994..2c9a2a0d573bdbc96da0a42f5cffd89c2dd3a662 100755 (executable)
@@ -144,6 +144,11 @@ set spobj {
        {                             fetch                         error}
        "const struct sess *"
     }
+    { obj.hits
+       RO INT
+       {                         hit fetch deliver                      }
+       "const struct sess *"
+    }
     { obj.http.
        RW HDR_OBJ
        {                         hit fetch                         error}
index 2aa6a80b238fd253b2458982a5736ddb8db400dc..eeff69f6312ac1d0e44a0f0e668500413bbceae6 100644 (file)
@@ -144,6 +144,13 @@ struct var vcc_vars[] = {
            0,
            VCL_MET_FETCH | VCL_MET_ERROR
        },
+       { "obj.hits", INT, 8,
+           "VRT_r_obj_hits(sp)",
+           NULL,
+           V_RO,
+           0,
+           VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
+       },
        { "obj.http.", HEADER, 9,
            "VRT_r_obj_http_(sp)",
            "VRT_l_obj_http_(sp, ",