Mailing List Archive

r3166 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl
Author: phk
Date: 2008-09-07 19:31:13 +0200 (Sun, 07 Sep 2008)
New Revision: 3166

Added:
trunk/varnish-cache/bin/varnishtest/tests/v00013.vtc
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_hash.c
trunk/varnish-cache/bin/varnishd/cache_vrt.c
trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc
trunk/varnish-cache/include/vrt_obj.h
trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Add obj.hits VRT variable which counts how many *previous* hits
this object has seen.

Idea for prefetching being used as workaround for #310



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2008-09-07 17:24:09 UTC (rev 3165)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2008-09-07 17:31:13 UTC (rev 3166)
@@ -285,6 +285,8 @@
/* Prefetch */
struct object *parent;
struct object *child;
+
+ int hits;
};

struct objhead {

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-09-07 17:24:09 UTC (rev 3165)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2008-09-07 17:31:13 UTC (rev 3166)
@@ -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 @@
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);

Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-09-07 17:24:09 UTC (rev 3165)
+++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2008-09-07 17:31:13 UTC (rev 3166)
@@ -552,6 +552,15 @@
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)
{

Modified: trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-09-07 17:24:09 UTC (rev 3165)
+++ trunk/varnish-cache/bin/varnishtest/tests/c00005.vtc 2008-09-07 17:31:13 UTC (rev 3166)
@@ -11,7 +11,7 @@
txresp -body "2222\n"
} -start

-varnish v1 -vcl+backend {
+varnish v1 -arg "-p vcl_trace=on" -vcl+backend {
acl acl1 {
"localhost";
}

Added: trunk/varnish-cache/bin/varnishtest/tests/v00013.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00013.vtc (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00013.vtc 2008-09-07 17:31:13 UTC (rev 3166)
@@ -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
+

Modified: trunk/varnish-cache/include/vrt_obj.h
===================================================================
--- trunk/varnish-cache/include/vrt_obj.h 2008-09-07 17:24:09 UTC (rev 3165)
+++ trunk/varnish-cache/include/vrt_obj.h 2008-09-07 17:31:13 UTC (rev 3166)
@@ -34,6 +34,7 @@
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 *);

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-09-07 17:24:09 UTC (rev 3165)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2008-09-07 17:31:13 UTC (rev 3166)
@@ -144,6 +144,11 @@
{ fetch error}
"const struct sess *"
}
+ { obj.hits
+ RO INT
+ { hit fetch deliver }
+ "const struct sess *"
+ }
{ obj.http.
RW HDR_OBJ
{ hit fetch error}

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-09-07 17:24:09 UTC (rev 3165)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2008-09-07 17:31:13 UTC (rev 3166)
@@ -144,6 +144,13 @@
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, ",