Commit 00b606f3 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Eliminate beresp.cachable VCL variable. Cacheability is now controlled

solely through the .ttl and .grace variables.

Add a parameter "shortlived", objects with ttl shorter than this
always go into transient (malloc) storage, just like pass objects do.

Enforce a minimum 1sec TTL for hit-for-pass.
parent 71c18e53
......@@ -104,6 +104,8 @@ struct lock { void *priv; }; // Opaque
#define DIGEST_LEN 32
/* Name of transient storage */
#define TRANSIENT_STORAGE "Transient"
/*--------------------------------------------------------------------
* Pointer aligment magic
......@@ -268,14 +270,13 @@ struct worker {
struct http *beresp;
struct http *resp;
unsigned cacheable;
double age;
double entered;
double ttl;
double grace;
/* This is only here so VRT can find it */
char *storage_hint;
const char *storage_hint;
/* Fetch stuff */
enum body_status body_status;
......
......@@ -379,7 +379,6 @@ cnt_error(struct sess *sp)
w = sp->wrk;
if (sp->obj == NULL) {
HSH_Prealloc(sp);
sp->wrk->cacheable = 0;
/* XXX: 1024 is a pure guess */
sp->obj = STV_NewObject(sp, NULL, 1024, 0,
params->http_headers);
......@@ -524,6 +523,13 @@ cnt_fetch(struct sess *sp)
sp->err_code = http_GetStatus(sp->wrk->beresp);
/*
* What does RFC2616 think about TTL ?
*/
sp->wrk->entered = TIM_real();
sp->wrk->age = 0;
sp->wrk->ttl = RFC2616_Ttl(sp);
/*
* Initial cacheability determination per [RFC2616, 13.4]
* We do not support ranges yet, so 206 is out.
......@@ -536,19 +542,15 @@ cnt_fetch(struct sess *sp)
case 302: /* Moved Temporarily */
case 410: /* Gone */
case 404: /* Not Found */
sp->wrk->cacheable = 1;
break;
default:
sp->wrk->cacheable = 0;
sp->wrk->ttl = sp->t_req - 1.;
break;
}
sp->wrk->entered = TIM_real();
sp->wrk->age = 0;
sp->wrk->ttl = RFC2616_Ttl(sp);
/* pass from vclrecv{} has negative TTL */
if (sp->objcore == NULL)
sp->wrk->cacheable = 0;
sp->wrk->ttl = sp->t_req - 1.;
sp->wrk->do_esi = 0;
sp->wrk->grace = NAN;
......@@ -561,11 +563,17 @@ cnt_fetch(struct sess *sp)
if (sp->objcore == NULL) {
/* This is a pass from vcl_recv */
sp->wrk->cacheable = 0;
pass = 1;
} else if (sp->handling == VCL_RET_PASS || !sp->wrk->cacheable) {
/* VCL may have fiddled this, but that doesn't help */
sp->wrk->ttl = sp->t_req - 1.;
} else if (sp->handling == VCL_RET_PASS) {
/* pass from vcl_fetch{} -> hit-for-pass */
/* XXX: the bereq was not filtered pass... */
pass = 1;
sp->objcore->flags |= OC_F_PASS;
/* Enforce a minimum TTL of 1 sec (if set from VCL) */
if (sp->wrk->ttl <= sp->t_req)
sp->wrk->ttl = sp->wrk->entered + params->default_ttl;
} else {
/* regular object */
pass = 0;
......@@ -633,7 +641,7 @@ cnt_fetch(struct sess *sp)
pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
/* Create Vary instructions */
if (sp->wrk->cacheable) {
if (sp->objcore != NULL) {
CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
vary = VRY_Create(sp, sp->wrk->beresp);
if (vary != NULL) {
......@@ -649,11 +657,18 @@ cnt_fetch(struct sess *sp)
*/
l += strlen("Content-Encoding: XxxXxxXxxXxxXxxXxx" + sizeof(void *));
if (sp->wrk->ttl < sp->t_req + params->shortlived ||
sp->objcore == NULL)
sp->wrk->storage_hint = TRANSIENT_STORAGE;
sp->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
sp->wrk->ttl, nhttp);
/* XXX: -> 513 */
CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);
sp->wrk->storage_hint = NULL;
/* VFP will update as needed */
sp->obj->gziped = sp->wrk->is_gzip;
if (vary != NULL) {
......@@ -687,7 +702,6 @@ cnt_fetch(struct sess *sp)
else
sp->obj->last_modified = sp->wrk->entered;
/* Use unmodified headers*/
i = FetchBody(sp, sp->wrk->beresp1);
......@@ -715,11 +729,6 @@ cnt_fetch(struct sess *sp)
sp->step = STP_RECV;
return (0);
case VCL_RET_PASS:
if (sp->obj->objcore != NULL)
sp->obj->objcore->flags |= OC_F_PASS;
if (sp->obj->ttl - sp->t_req < params->default_ttl)
sp->obj->ttl = sp->t_req + params->default_ttl;
break;
case VCL_RET_DELIVER:
break;
case VCL_RET_ERROR:
......@@ -730,7 +739,7 @@ cnt_fetch(struct sess *sp)
WRONG("Illegal action in vcl_fetch{}");
}
if (sp->wrk->cacheable) {
if (sp->obj->objcore != NULL) {
EXP_Insert(sp->obj);
AN(sp->obj->objcore);
AN(sp->obj->objcore->ban);
......
......@@ -195,7 +195,6 @@ VRT_r_##dir##_##onm(const struct sess *sp) \
return (sp->wrk->field); \
}
VBERESP(beresp, unsigned, cacheable, cacheable)
VBERESP(beresp, unsigned, do_esi, do_esi)
VBERESP(beresp, unsigned, do_gzip, do_gzip)
VBERESP(beresp, unsigned, do_gunzip, do_gunzip)
......
......@@ -102,7 +102,7 @@ sub vcl_miss {
}
sub vcl_fetch {
if (!beresp.cacheable) {
if (beresp.ttl <= 0s) {
return (pass);
}
if (beresp.http.Set-Cookie) {
......
......@@ -205,6 +205,8 @@ struct params {
unsigned gzip_level;
double critbit_cooloff;
double shortlived;
};
/*
......
......@@ -842,6 +842,12 @@ static const struct parspec input_parspec[] = {
" just a waste of memory.",
EXPERIMENTAL,
"32768", "Bytes" },
{ "shortlived", tweak_timeout_double,
&master.shortlived, 0, UINT_MAX,
"Objects created with TTL shorter than this are always "
"put in transient storage.\n",
0,
"10.0", "s" },
{ "critbit_cooloff", tweak_timeout_double,
&master.critbit_cooloff, 60, 254,
"How long time the critbit hasher keeps deleted objheads "
......
......@@ -47,8 +47,6 @@ SVNID("$Id$")
#include "cli_priv.h"
#include "vrt_obj.h"
#define TRANSIENT_NAME "Transient"
static VTAILQ_HEAD(, stevedore) stevedores =
VTAILQ_HEAD_INITIALIZER(stevedores);
......@@ -91,7 +89,7 @@ stv_pick_stevedore(const char *hint)
if (!strcmp(stv->ident, hint))
return (stv);
}
if (!strcmp(TRANSIENT_NAME, hint))
if (!strcmp(TRANSIENT_STORAGE, hint))
return (stv_transient);
}
/* pick a stevedore and bump the head along */
......@@ -268,10 +266,7 @@ STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, double ttl,
ltot = sizeof *o + wsl + lhttp;
if (!sp->wrk->cacheable)
stv = stv_transient;
else
stv = stv_pick_stevedore(hint);
stv = stv_pick_stevedore(hint);
AN(stv->allocobj);
o = stv->allocobj(stv, sp, ltot, &soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
......@@ -477,7 +472,7 @@ STV_Config(const char *spec)
else if (ac != 0)
ARGV_ERR("(-s%s) too many arguments\n", stv->name);
if (!strcmp(stv->ident, TRANSIENT_NAME)) {
if (!strcmp(stv->ident, TRANSIENT_STORAGE)) {
stv->transient = 1;
AZ(stv_transient);
stv_transient = stv;
......@@ -497,9 +492,9 @@ STV_Config_Transient(void)
ASSERT_MGT();
VTAILQ_FOREACH(stv, &stevedores, list)
if (!strcmp(stv->ident, TRANSIENT_NAME))
if (!strcmp(stv->ident, TRANSIENT_STORAGE))
return;
STV_Config(TRANSIENT_NAME "=malloc");
STV_Config(TRANSIENT_STORAGE "=malloc");
}
/*--------------------------------------------------------------------*/
......@@ -539,7 +534,7 @@ stv_find(const char *nm)
VTAILQ_FOREACH(stv, &stevedores, list)
if (!strcmp(stv->ident, nm))
return (stv);
if (!strcmp(TRANSIENT_NAME, nm))
if (!strcmp(TRANSIENT_STORAGE, nm))
return (stv_transient);
return (NULL);
}
......
......@@ -1436,7 +1436,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
/* XXX: temporary sanity */
AN(sp->objcore);
AN(sp->wrk->cacheable);
AN(sp->wrk->ttl >= 0);
sg = NULL;
st = smp_allocx(stv, ltot, &sg);
......
......@@ -57,7 +57,6 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_fetch {
if (beresp.status == 502) {
set beresp.cacheable = true;
set beresp.ttl = 10m;
}
}
......
......@@ -21,7 +21,7 @@ varnish v1 -vcl+backend {
}
sub vcl_fetch {
if (beresp.status == 303) {
set beresp.cacheable = true;
set beresp.ttl = 3m;
set beresp.http.X-Magic-Redirect = "1";
}
}
......
......@@ -14,7 +14,6 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_fetch {
if (beresp.status == 303) {
set beresp.cacheable = true;
set beresp.ttl = 60 s;
set beresp.http.X-Magic-Redirect = "1";
set req.url = beresp.http.Location;
......
......@@ -19,7 +19,7 @@ server s1 {
varnish v1 -vcl+backend {
sub vcl_fetch {
set beresp.cacheable = false;
set beresp.ttl = 0s;
}
} -start
......
......@@ -52,7 +52,6 @@ varnish v1 -vcl {
sub vcl_fetch {
set beresp.ttl = 1s;
set beresp.grace = 1m;
set beresp.cacheable = true;
}
} -start
......
......@@ -20,7 +20,6 @@ varnish v1 -vcl+backend {
sub vcl_fetch {
set beresp.ttl = 1s;
set beresp.grace = 10m;
set beresp.cacheable = true;
if (beresp.http.foo == "2")
{
set beresp.saintmode = 2s;
......
......@@ -292,12 +292,6 @@ sp_variables = (
( 'fetch',),
'const struct sess *'
),
('beresp.cacheable',
'BOOL',
( 'fetch',),
( 'fetch',),
'const struct sess *'
),
('beresp.do_esi',
'BOOL',
( 'fetch',),
......
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