From: phk Date: Mon, 19 Jan 2009 11:45:03 +0000 (+0000) Subject: Add a new paramter "purge_hash" which defaults to "off". X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2532e48514a2dd6ae5c5769f82a0f39c3c4d800c;p=varnish Add a new paramter "purge_hash" which defaults to "off". Only save the hash-string in the session workspace and objects when this paramter is set to "on". For sites with many small objects, this will save significant VM. When this paramter is set to "off", the "purge.hash" facility will not work, but this should not be a problem, because the new purging facility allow much more expressive purging, the typical case being: purge req.http.host ~ www.foo.com && req.url ~ "article2383" git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3526 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_ban.c b/varnish-cache/bin/varnishd/cache_ban.c index 56b8000e..39732c8d 100644 --- a/varnish-cache/bin/varnishd/cache_ban.c +++ b/varnish-cache/bin/varnishd/cache_ban.c @@ -607,6 +607,14 @@ ccf_purge_hash(struct cli *cli, const char * const *av, void *priv) const char *aav[6]; (void)priv; + if (!save_hash) { + cli_out(cli, + "purge.hash not possible.\n" + "Set the \"purge_hash\" parameter to on\n" + "and restart the varnish worker process to enable.\n"); + cli_result(cli, CLIS_CANT); + return; + } aav[0] = NULL; aav[1] = "purge"; aav[2] = "obj.hash"; diff --git a/varnish-cache/bin/varnishd/cache_hash.c b/varnish-cache/bin/varnishd/cache_hash.c index 9db6d813..eb362dfd 100644 --- a/varnish-cache/bin/varnishd/cache_hash.c +++ b/varnish-cache/bin/varnishd/cache_hash.c @@ -69,6 +69,7 @@ #include "vsha256.h" static const struct hash_slinger *hash; +unsigned save_hash; double HSH_Grace(double g) @@ -151,6 +152,8 @@ HSH_Copy(const struct sess *sp, struct objhead *oh) CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + if (!save_hash) + return; oh->hash = malloc(sp->lhashptr); XXXAN(oh->hash); @@ -172,6 +175,10 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount) char *p; unsigned u; + SHA256_Init(sp->wrk->sha256ctx); + if (!save_hash) + return; + /* Allocate the pointers we need, align properly. */ sp->lhashptr = 1; /* space for NUL */ sp->ihashptr = 0; @@ -184,7 +191,6 @@ HSH_Prepare(struct sess *sp, unsigned nhashcount) if (u) p += sizeof(const char *) - u; sp->hashptr = (void*)p; - SHA256_Init(sp->wrk->sha256ctx); } void @@ -196,6 +202,15 @@ HSH_AddString(struct sess *sp, const char *str) str = ""; l = strlen(str); + SHA256_Update(sp->wrk->sha256ctx, str, l); + SHA256_Update(sp->wrk->sha256ctx, "#", 1); + + if (params->log_hash) + WSP(sp, SLT_Hash, "%s", str); + + if (!save_hash) + return; + /* * XXX: handle this by bouncing sp->vcl->nhashcount when it fails * XXX: and dispose of this request either by reallocating the @@ -207,8 +222,6 @@ HSH_AddString(struct sess *sp, const char *str) sp->hashptr[sp->ihashptr + 1] = str + l; sp->ihashptr += 2; sp->lhashptr += l + 1; - SHA256_Update(sp->wrk->sha256ctx, str, l); - SHA256_Update(sp->wrk->sha256ctx, "#", 1); } struct object * @@ -284,8 +297,6 @@ HSH_Lookup(struct sess *sp) if (o->hits < INT_MAX) o->hits++; Lck_Unlock(&oh->mtx); - if (params->log_hash) - WSP(sp, SLT_Hash, "%s", oh->hash); (void)hash->deref(oh); return (o); } @@ -315,8 +326,6 @@ HSH_Lookup(struct sess *sp) grace_o->refcnt++; } Lck_Unlock(&oh->mtx); - if (params->log_hash) - WSP(sp, SLT_Hash, "%s", oh->hash); /* * XXX: This may be too early, relative to pass objects. * XXX: possibly move to when we commit to have it in the cache. @@ -467,6 +476,7 @@ void HSH_Init(void) { + save_hash = params->save_hash; hash = heritage.hash; if (hash->start != NULL) hash->start(); diff --git a/varnish-cache/bin/varnishd/hash_slinger.h b/varnish-cache/bin/varnishd/hash_slinger.h index 508bb69d..85a1b08b 100644 --- a/varnish-cache/bin/varnishd/hash_slinger.h +++ b/varnish-cache/bin/varnishd/hash_slinger.h @@ -105,4 +105,6 @@ struct objhead { #define hoh_head u.n.u_n_hoh_head #define hoh_digest u.n.u_n_hoh_digest }; + +extern unsigned save_hash; #endif /* VARNISH_CACHE_CHILD */ diff --git a/varnish-cache/bin/varnishd/heritage.h b/varnish-cache/bin/varnishd/heritage.h index 8be6f7af..edeec27e 100644 --- a/varnish-cache/bin/varnishd/heritage.h +++ b/varnish-cache/bin/varnishd/heritage.h @@ -177,6 +177,9 @@ struct params { /* Log hash string to shm */ unsigned log_hash; + /* Log hash string to shm */ + unsigned save_hash; + /* Log local socket address to shm */ unsigned log_local_addr; diff --git a/varnish-cache/bin/varnishd/mgt_param.c b/varnish-cache/bin/varnishd/mgt_param.c index 56c434da..1a9e03b0 100644 --- a/varnish-cache/bin/varnishd/mgt_param.c +++ b/varnish-cache/bin/varnishd/mgt_param.c @@ -100,7 +100,8 @@ tweak_generic_timeout_double(struct cli *cli, volatile double *dst, const char * if (arg != NULL) { u = strtod(arg, NULL); if (u < 0) { - cli_out(cli, "Timeout must be greater or equal to zero\n"); + cli_out(cli, + "Timeout must be greater or equal to zero\n"); cli_result(cli, CLIS_PARAM); return; } @@ -714,6 +715,12 @@ static const struct parspec input_parspec[] = { "Log the hash string to shared memory log.\n", 0, "off", "bool" }, + { "purge_hash", tweak_bool, &master.save_hash, 0, 0, + "Enable purge.hash command.\n" + "NB: this increases storage requirement per object " + "by the length of the hash string.\n", + MUST_RESTART, + "off", "bool" }, { "log_local_address", tweak_bool, &master.log_local_addr, 0, 0, "Log the local address on the TCP connection in the " "SessionOpen shared memory record.\n", diff --git a/varnish-cache/bin/varnishtest/tests/c00007.vtc b/varnish-cache/bin/varnishtest/tests/c00007.vtc index f45b639b..f0e69b96 100644 --- a/varnish-cache/bin/varnishtest/tests/c00007.vtc +++ b/varnish-cache/bin/varnishtest/tests/c00007.vtc @@ -11,7 +11,11 @@ server s1 { txresp -body "11111\n" } -start -varnish v1 -vcl+backend { } -start +varnish v1 -arg "-ppurge_hash=off" -vcl+backend { } -start +varnish v1 -clierr 300 "purge.hash foo" +varnish v1 -stop +varnish v1 -cliok "param.set purge_hash on" +varnish v1 -start client c1 { txreq -url "/foo" @@ -22,7 +26,7 @@ client c1 { client c1 -run -varnish v1 -cli "purge.hash foo" +varnish v1 -cliok "purge.hash foo" client c1 { txreq -url "/foo" diff --git a/varnish-cache/bin/varnishtest/tests/c00019.vtc b/varnish-cache/bin/varnishtest/tests/c00019.vtc index 278e3e3f..478ff618 100644 --- a/varnish-cache/bin/varnishtest/tests/c00019.vtc +++ b/varnish-cache/bin/varnishtest/tests/c00019.vtc @@ -13,7 +13,7 @@ server s1 { txresp -hdr "foo: 3" -body "foo3" } -start -varnish v1 -vcl+backend {} -start +varnish v1 -arg "-p purge_hash=on" -vcl+backend {} -start varnish v1 -cliok "purge.url FOO"