Commit a7ed1d77 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add obj.hits VRT variable which counts how many *previous* hits

this object has seen.

Idea for prefetching being used as workaround for #310 



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@3166 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent b44f7a14
......@@ -285,6 +285,8 @@ struct object {
/* Prefetch */
struct object *parent;
struct object *child;
int hits;
};
struct objhead {
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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";
}
......
# $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
......@@ -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 *);
......
......@@ -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}
......
......@@ -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, ",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment