]> err.no Git - varnish/commitdiff
Add a boolean parameter "purge_dups", to make it possible to mark earlier
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 20 Oct 2008 15:01:37 +0000 (15:01 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 20 Oct 2008 15:01:37 +0000 (15:01 +0000)
bans of the same regexp as "gone" to save duplicate regexp checking.

Prodded to by: jodok

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3329 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_ban.c
varnish-cache/bin/varnishd/heritage.h
varnish-cache/bin/varnishd/mgt_param.c
varnish-cache/include/stat_field.h

index 77ca63240b959f9b3195700520a5c2c7add0bf38..ae5c4cf04a26ace508ceafdcc3b8a4463a67199d 100644 (file)
@@ -49,6 +49,8 @@ struct ban {
 #define BAN_MAGIC              0x700b08ea
        VTAILQ_ENTRY(ban)       list;
        unsigned                refcount;
+       int                     flags;
+#define BAN_F_GONE             (1 << 0)
        regex_t                 regexp;
        char                    *ban;
        int                     hash;
@@ -68,8 +70,9 @@ static struct ban * volatile ban_start;
 int
 BAN_Add(struct cli *cli, const char *regexp, int hash)
 {
-       struct ban *b;
+       struct ban *b, *bi, *be;
        char buf[512];
+       unsigned pcount;
        int i;
 
        ALLOC_OBJ(b, BAN_MAGIC);
@@ -97,6 +100,35 @@ BAN_Add(struct cli *cli, const char *regexp, int hash)
        ban_start = b;
        VSL_stats->n_purge++;
        VSL_stats->n_purge_add++;
+
+       if (params->purge_dups) {
+               be = VTAILQ_LAST(&ban_head, banhead);
+               be->refcount++;
+       } else
+               be = NULL;
+       UNLOCK(&ban_mtx);
+
+       if (be == NULL)
+               return (0);
+
+       /* Hunt down duplicates, and mark them as gone */
+       bi = b;
+       pcount = 0;
+       while(bi != be) {
+               bi = VTAILQ_NEXT(bi, list);
+               if (bi->flags & BAN_F_GONE)
+                       continue;
+               if (b->hash != bi->hash)
+                       continue;
+               if (strcmp(b->ban, bi->ban))
+                       continue;
+               bi->flags |= BAN_F_GONE;
+               pcount++;
+       }
+       LOCK(&ban_mtx);
+       be->refcount--;
+       /* XXX: We should check if the tail can be removed */
+       VSL_stats->n_purge_dups += pcount;
        UNLOCK(&ban_mtx);
 
        return (0);
@@ -168,7 +200,8 @@ BAN_CheckObject(struct object *o, const char *url, const char *hash)
        tests = 0;
        for (b = b0; b != o->ban; b = VTAILQ_NEXT(b, list)) {
                tests++;
-               if (!regexec(&b->regexp, b->hash ? hash : url, 0, NULL, 0))
+               if (!(b->flags & BAN_F_GONE) &&
+                   !regexec(&b->regexp, b->hash ? hash : url, 0, NULL, 0))
                        break;
        }
 
@@ -227,8 +260,8 @@ ccf_purge_list(struct cli *cli, const char * const *av, void *priv)
        for (b0 = ban_start; b0 != NULL; b0 = VTAILQ_NEXT(b0, list)) {
                if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL)
                        break;
-               cli_out(cli, "%5u %s \"%s\"\n",
-                   b0->refcount,
+               cli_out(cli, "%5u %d %s \"%s\"\n",
+                   b0->refcount, b0->flags,
                    b0->hash ? "hash" : "url ",
                    b0->ban);
        }
index 14d482e3986a4145b07aae53441c63c0010b53a6..fd7dada8b5e2f0a889606419e62af6bba26dbd7f 100644 (file)
@@ -183,6 +183,9 @@ struct params {
        /* Amount of time to sleep when running out of file
           descriptors.  In msecs */
        unsigned                accept_fd_holdoff;
+
+       /* Get rid of duplicate purges */
+       unsigned                purge_dups;
 };
 
 extern volatile struct params *params;
index 02bee6823c52ed935097fe9b984c27248ec923b9..ae5e0672789bbf6f06eee6773997387d396e8666 100644 (file)
@@ -825,6 +825,10 @@ static const struct parspec parspec[] = {
                "The TTL assigned to the synthesized error pages\n",
                0,
                "0", "seconds" },
+       { "purge_dups", tweak_bool, &master.purge_dups, 0, 0,
+               "Detect and eliminate duplicate purges.\n",
+               0,
+               "off", "bool" },
        { NULL, NULL, NULL }
 };
 
index b0f496b1e5116060c0a7cffbdd5e7d9929e399a0..127e30b907b3cd26283a866507d99a9febaf211a 100644 (file)
@@ -125,3 +125,4 @@ MAC_STAT(n_purge_add,               uint64_t, 'a', "N new purges added")
 MAC_STAT(n_purge_retire,       uint64_t, 'a', "N old purges deleted")
 MAC_STAT(n_purge_obj_test,     uint64_t, 'a', "N objects tested")
 MAC_STAT(n_purge_re_test,      uint64_t, 'a', "N regexps tested against")
+MAC_STAT(n_purge_dups,         uint64_t, 'a', "N duplicate purges removed")