]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
- Added internal support for cache digest (store_digest). The digest is
authorrousskov <>
Fri, 3 Apr 1998 00:11:20 +0000 (00:11 +0000)
committerrousskov <>
Fri, 3 Apr 1998 00:11:20 +0000 (00:11 +0000)
  maintained as a "mirror" of store_hash table. storeHashInsert/Delete forward
  public key objects to the store_digest object. Sending digests to other
  caches is not yet supported. Periodic digest rebuild is not yet supported.

- Rudimental reporting for store digest is done via cache manager.

12 files changed:
src/CacheDigest.cc
src/Makefile.in
src/cache_cf.cc
src/enums.h
src/globals.h
src/neighbors.cc
src/protos.h
src/squid.h
src/store.cc
src/store_digest.cc [new file with mode: 0644]
src/store_rebuild.cc
src/test_cache_digest.cc

index f05aaa1f09b852d2fbcfc3e3934b22e0c82f3194..af963beee7f981edf874a9f224141637a28c8599 100644 (file)
@@ -1,8 +1,8 @@
 
 /*
- * $Id: CacheDigest.cc,v 1.6 1998/04/01 07:14:05 rousskov Exp $
+ * $Id: CacheDigest.cc,v 1.7 1998/04/02 17:11:20 rousskov Exp $
  *
- * DEBUG: section ??    Cache Digest
+ * DEBUG: section 70    Cache Digest
  * AUTHOR: Alex Rousskov
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -126,6 +126,30 @@ cacheDigestUtil(const CacheDigest * cd, int *bit_cnt_p, int *on_cnt_p)
     return xpercent(on_count, bit_count);
 }
 
+void
+cacheDigestReport(CacheDigest *cd, const char *label, StoreEntry * e)
+{
+    int bit_count, on_count;
+    assert(cd && e);
+    cacheDigestUtil(cd, &bit_count, &on_count);
+    storeAppendPrintf(e, "%s digest: size: %d bytes.\n",
+       label ? label : "",
+       bit_count/8
+    );
+    storeAppendPrintf(e, "\t entries: count: %d capacity: %d util: %d%%\n",
+       cd->count,
+       cd->capacity,
+       xpercentInt(cd->count, cd->capacity)
+    );
+    storeAppendPrintf(e, "\t deletion attempts: %d\n", 
+       cd->del_count
+    );
+    storeAppendPrintf(e, "\t bits: on: %d capacity: %d util: %d%%\n", 
+       on_count, bit_count,
+       xpercentInt(on_count, bit_count)
+    );
+}
+
 static void
 cacheDigestHashKey(int bit_count, const char *key)
 {
index afc868140e354ec9435efda4a0d8733fb4b262df..add1d6b1533cfc5ed2514aab8715930b28f3c2f8 100644 (file)
@@ -1,7 +1,7 @@
 #
 #  Makefile for the Squid Object Cache server
 #
-#  $Id: Makefile.in,v 1.140 1998/03/30 20:42:40 rousskov Exp $
+#  $Id: Makefile.in,v 1.141 1998/04/02 17:11:21 rousskov Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -72,6 +72,7 @@ OBJS          = \
                asn.o \
                @ASYNC_OBJS@ \
                cache_cf.o \
+               CacheDigest.o \
                cbdata.o \
                client_db.o \
                client_side.o \
@@ -132,6 +133,7 @@ OBJS                = \
                store.o \
                store_clean.o \
                store_client.o \
+               store_digest.o \
                store_dir.o \
                store_key_md5.o \
                store_log.o \
index 88469944ea872fa17ee32107a259eb3643ac6314..c253a58cb9da13e838c40783b3afe3d474d10821 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.269 1998/03/31 05:37:34 wessels Exp $
+ * $Id: cache_cf.cc,v 1.270 1998/04/02 17:11:22 rousskov Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -681,6 +681,8 @@ parse_peer(peer ** head)
            EBIT_SET(p->options, NEIGHBOR_PROXY_ONLY);
        } else if (!strcasecmp(token, "no-query")) {
            EBIT_SET(p->options, NEIGHBOR_NO_QUERY);
+       } else if (!strcasecmp(token, "no-digest")) {
+           EBIT_SET(p->options, NEIGHBOR_NO_DIGEST);
        } else if (!strcasecmp(token, "multicast-responder")) {
            EBIT_SET(p->options, NEIGHBOR_MCAST_RESPONDER);
        } else if (!strncasecmp(token, "weight=", 7)) {
index fed737442d57f3522ee6f1055138c7298c08a36b..4294742fff440fdfe02bba99dde5d0162cbe3abe 100644 (file)
@@ -435,6 +435,7 @@ enum {
 enum {
     NEIGHBOR_PROXY_ONLY,
     NEIGHBOR_NO_QUERY,
+    NEIGHBOR_NO_DIGEST,
     NEIGHBOR_DEFAULT_PARENT,
     NEIGHBOR_ROUNDROBIN,
     NEIGHBOR_MCAST_RESPONDER,
index b73e19c42d3482ef014203bbe20de6a2a1629c13..95e5983dd6650b513c229ed538602be01280a882 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: globals.h,v 1.48 1998/04/01 00:13:14 wessels Exp $
+ * $Id: globals.h,v 1.49 1998/04/02 17:11:23 rousskov Exp $
  */
 
 extern FILE *debug_log;                /* NULL */
@@ -99,3 +99,4 @@ extern dlink_list store_list;
 extern const String StringNull;        /* { 0, 0, NULL } */
 extern int hot_obj_count;      /* 0 */
 extern int _db_level;
+extern CacheDigest *store_digest; /* NULL */
index 20de57e7f751d8d9c1913024e9965cf3aa803c41..6d8ccf2affc3f3150d8062e3f0cd410eabd61102 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: neighbors.cc,v 1.188 1998/04/02 07:40:31 wessels Exp $
+ * $Id: neighbors.cc,v 1.189 1998/04/02 17:11:24 rousskov Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -1006,6 +1006,8 @@ dump_peer_options(StoreEntry * sentry, peer * p)
        storeAppendPrintf(sentry, " proxy-only");
     if (EBIT_TEST(p->options, NEIGHBOR_NO_QUERY))
        storeAppendPrintf(sentry, " no-query");
+    if (EBIT_TEST(p->options, NEIGHBOR_NO_DIGEST))
+       storeAppendPrintf(sentry, " no-digest");
     if (EBIT_TEST(p->options, NEIGHBOR_DEFAULT_PARENT))
        storeAppendPrintf(sentry, " default");
     if (EBIT_TEST(p->options, NEIGHBOR_ROUNDROBIN))
index 1d491e482466acf280c787040f9234400e8f9ea0..61634364bb90468aa6031454b22476cb36147bae 100644 (file)
@@ -696,6 +696,12 @@ extern HASHCMP storeKeyHashCmp;
  */
 extern EVH storeDirClean;
 
+/* store_digest.c */
+extern void storeDigestInit();
+extern void storeDigestRebuild();
+extern void storeDigestReport();
+
+
 /*
  * store_dir.c
  */
@@ -900,6 +906,7 @@ extern int cacheDigestTest(const CacheDigest * cd, const cache_key * key);
 extern void cacheDigestAdd(CacheDigest * cd, const cache_key * key);
 extern void cacheDigestDel(CacheDigest * cd, const cache_key * key);
 extern double cacheDigestUtil(const CacheDigest * cd, int *bit_cnt_p, int *on_cnt_p);
+extern void cacheDigestReport(CacheDigest *cd, const char *label, StoreEntry * e);
 
 /*
  * prototypes for system functions missing from system includes
index 406434be529b7a0c28bbbbaf292874749e1fbbdb..7f96a5c0358e5b1d3b353425f2ffefd47a1ff73e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: squid.h,v 1.165 1998/03/17 04:00:16 wessels Exp $
+ * $Id: squid.h,v 1.166 1998/04/02 17:11:25 rousskov Exp $
  *
  * AUTHOR: Duane Wessels
  *
@@ -355,4 +355,11 @@ struct rusage {
 #if SQUID_SNMP
 extern struct snmp_mib_tree *Mib;
 #endif
+
+/*
+ * maintain a digest of cache contents and send the digest to neighbors upon
+ * request; if disabled we still can request digests from other caches
+ */
+#define SQUID_MAINTAIN_CACHE_DIGEST 1
+
 #endif /* SQUID_H */
index 4653dae41dd5dedc19ec9575ac5802c651a386fe..e4f8f484762515a4b86a424aa9173df6cae5a612 100644 (file)
@@ -1,8 +1,8 @@
 
 /*
- * $Id: store.cc,v 1.399 1998/03/29 08:51:03 wessels Exp $
+ * $Id: store.cc,v 1.400 1998/04/02 17:11:26 rousskov Exp $
  *
- * DEBUG: section 20    Storeage Manager
+ * DEBUG: section 20    Storage Manager
  * AUTHOR: Harvest Derived
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -254,11 +254,15 @@ storeHashInsert(StoreEntry * e, const cache_key * key)
     e->key = storeKeyDup(key);
     hash_join(store_table, (hash_link *) e);
     dlinkAdd(e, &e->lru, &store_list);
+    if (store_digest && !EBIT_TEST(e->flag, KEY_PRIVATE))
+       cacheDigestAdd(store_digest, e->key);
 }
 
 static void
 storeHashDelete(StoreEntry * e)
 {
+    if (store_digest && !EBIT_TEST(e->flag, KEY_PRIVATE))
+       cacheDigestDel(store_digest, e->key);
     hash_remove_link(store_table, (hash_link *) e);
     dlinkDelete(&e->lru, &store_list);
     storeKeyFree(e->key);
@@ -370,8 +374,8 @@ storeSetPrivateKey(StoreEntry * e)
        newkey = storeKeyPrivate("JUNK", METHOD_NONE, getKeyCounter(METHOD_NONE));
     }
     assert(hash_lookup(store_table, newkey) == NULL);
-    storeHashInsert(e, newkey);
     EBIT_SET(e->flag, KEY_PRIVATE);
+    storeHashInsert(e, newkey);
 }
 
 void
@@ -392,8 +396,8 @@ storeSetPublicKey(StoreEntry * e)
     }
     if (e->key)
        storeHashDelete(e);
-    storeHashInsert(e, newkey);
     EBIT_CLR(e->flag, KEY_PRIVATE);
+    storeHashInsert(e, newkey);
     if (e->swap_file_number > -1)
        storeDirSwapLog(e, SWAP_LOG_ADD);
 }
@@ -821,6 +825,7 @@ storeInit(void)
     storeInitHashValues();
     store_table = hash_create(storeKeyHashCmp,
        store_hash_buckets, storeKeyHashHash);
+    storeDigestInit();
     storeLogOpen();
     if (storeVerifyCacheDirs() < 0) {
        xstrncpy(tmp_error_buf,
@@ -931,6 +936,9 @@ storeFreeMemory(void)
     hashFreeItems(store_table, destroy_StoreEntry);
     hashFreeMemory(store_table);
     store_table = NULL;
+    if (store_digest)
+       cacheDigestDestroy(store_digest);
+    store_digest = NULL;
 }
 
 int
diff --git a/src/store_digest.cc b/src/store_digest.cc
new file mode 100644 (file)
index 0000000..68ab82f
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * $Id: store_digest.cc,v 1.1 1998/04/02 17:11:27 rousskov Exp $
+ *
+ * DEBUG: section 71    Store Digest Manager
+ * AUTHOR: Alex Rousskov
+ *
+ * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
+ * --------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from the
+ *  Internet community.  Development is led by Duane Wessels of the
+ *  National Laboratory for Applied Network Research and funded by
+ *  the National Science Foundation.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  
+ */
+
+#include "squid.h"
+
+void
+storeDigestInit()
+{
+    /*
+     * To-Do: Bloom proved that the optimal filter utilization is 50% (half of
+     * the bits are off). However, we do not have a formula to calculate the 
+     * number of _entries_ we want to pre-allocate for.
+     * Use 1.5*max#entries because 2*max#entries gives about 40% utilization.
+     */
+    const int cap = (int)(1.5 * Config.Swap.maxSize / Config.Store.avgObjectSize);
+#if SQUID_MAINTAIN_CACHE_DIGEST
+    store_digest = cacheDigestCreate(cap);
+#else
+    store_digest = NULL;
+#endif
+    cachemgrRegister("store_digest", "Store Digest",
+        storeDigestReport, 0);
+}
+
+/* rebuilds digest from scratch */
+void
+storeDigestRebuild()
+{
+    assert(store_digest);
+}
+
+void
+storeDigestReport(StoreEntry *e)
+{
+    if (store_digest) {
+       cacheDigestReport(store_digest, "store", e);
+    } else {
+       storeAppendPrintf(e, "store digest: disabled.\n");
+    }
+}
+
index 80360a31e498b779619dc1df07eef3a33f7c280d..695555d39994ac7977562419c473da69690fd5e9 100644 (file)
@@ -1,3 +1,33 @@
+/*
+ * $Id: store_rebuild.cc,v 1.27 1998/04/02 17:11:27 rousskov Exp $
+ *
+ * DEBUG: section 20    Store Rebuild Routines
+ * AUTHOR: Duane Wessels
+ *
+ * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
+ * --------------------------------------------------------
+ *
+ *  Squid is the result of efforts by numerous individuals from the
+ *  Internet community.  Development is led by Duane Wessels of the
+ *  National Laboratory for Applied Network Research and funded by
+ *  the National Science Foundation.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *  
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *  
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  
+ */
+
 #include "squid.h"
 
 #define STORE_META_BUFSZ 4096
@@ -511,7 +541,6 @@ storeAddDiskRestore(const cache_key * key,
     /* if you call this you'd better be sure file_number is not 
      * already in use! */
     e = new_StoreEntry(STORE_ENTRY_WITHOUT_MEMOBJ, NULL, NULL);
-    storeHashInsert(e, key);
     e->store_status = STORE_OK;
     storeSetMemStatus(e, NOT_IN_MEMORY);
     e->swap_status = SWAPOUT_DONE;
@@ -531,6 +560,7 @@ storeAddDiskRestore(const cache_key * key,
     e->ping_status = PING_NONE;
     EBIT_CLR(e->flag, ENTRY_VALIDATED);
     storeDirMapBitSet(e->swap_file_number);
+    storeHashInsert(e, key); /* do it after we clear KEY_PRIVATE */
     return e;
 }
 
index b2e46c5c298a1bb86fca986107b9646482b1b265..af43bb6eba941a739075018fa4e7af6a7136931d 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: test_cache_digest.cc,v 1.15 1998/04/01 18:02:19 rousskov Exp $
+ * $Id: test_cache_digest.cc,v 1.16 1998/04/02 17:11:28 rousskov Exp $
  *
  * AUTHOR: Alex Rousskov
  *
@@ -348,22 +348,6 @@ cacheReport(Cache * cache)
        cache->name, cache->count, cache->req_count,
        cache->bad_add_count, cache->bad_del_count);
 
-    if (cache->digest) {
-       int bit_count, on_count;
-       cacheDigestUtil(cache->digest, &bit_count, &on_count);
-       fprintf(stdout, "%s: digest entries: cnt: %d (-=%d) cap: %d util: %d%% size: %d b\n", 
-           cache->name, 
-           cache->digest->count, cache->digest->del_count,
-           cache->digest->capacity,
-           xpercentInt(cache->digest->count, cache->digest->capacity),
-           bit_count/8
-       );
-       fprintf(stdout, "%s: digest bits: on: %d cap: %d util: %d%%\n", 
-           cache->name,
-           on_count, bit_count,
-           xpercentInt(on_count, bit_count)
-       );
-    }
 }
 
 static void