r3714 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Tue Feb 10 14:33:28 CET 2009
Author: tfheen
Date: 2009-02-10 14:33:28 +0100 (Tue, 10 Feb 2009)
New Revision: 3714
Modified:
branches/2.0/varnish-cache/bin/varnishd/cache_ban.c
branches/2.0/varnish-cache/bin/varnishd/cache_hash.c
branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h
branches/2.0/varnish-cache/bin/varnishd/heritage.h
branches/2.0/varnish-cache/bin/varnishd/mgt_param.c
branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc
branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc
Log:
Merge r3526: 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"
Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-09 13:25:00 UTC (rev 3713)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 13:33:28 UTC (rev 3714)
@@ -607,6 +607,14 @@
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";
Modified: branches/2.0/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-09 13:25:00 UTC (rev 3713)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_hash.c 2009-02-10 13:33:28 UTC (rev 3714)
@@ -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 @@
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 @@
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 @@
if (u)
p += sizeof(const char *) - u;
sp->hashptr = (void*)p;
- SHA256_Init(sp->wrk->sha256ctx);
}
void
@@ -196,6 +202,15 @@
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 @@
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 @@
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 @@
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 @@
HSH_Init(void)
{
+ save_hash = params->save_hash;
hash = heritage.hash;
if (hash->start != NULL)
hash->start();
Modified: branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-09 13:25:00 UTC (rev 3713)
+++ branches/2.0/varnish-cache/bin/varnishd/hash_slinger.h 2009-02-10 13:33:28 UTC (rev 3714)
@@ -105,4 +105,6 @@
#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 */
Modified: branches/2.0/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-09 13:25:00 UTC (rev 3713)
+++ branches/2.0/varnish-cache/bin/varnishd/heritage.h 2009-02-10 13:33:28 UTC (rev 3714)
@@ -177,6 +177,9 @@
/* 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;
Modified: branches/2.0/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-09 13:25:00 UTC (rev 3713)
+++ branches/2.0/varnish-cache/bin/varnishd/mgt_param.c 2009-02-10 13:33:28 UTC (rev 3714)
@@ -100,7 +100,8 @@
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 @@
"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",
Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc 2009-02-09 13:25:00 UTC (rev 3713)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00007.vtc 2009-02-10 13:33:28 UTC (rev 3714)
@@ -11,7 +11,11 @@
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 -run
-varnish v1 -cli "purge.hash foo"
+varnish v1 -cliok "purge.hash foo"
client c1 {
txreq -url "/foo"
Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-09 13:25:00 UTC (rev 3713)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-02-10 13:33:28 UTC (rev 3714)
@@ -13,7 +13,7 @@
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"
More information about the varnish-commit
mailing list