/*
- * $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/
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)
{
#
# 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:
#
asn.o \
@ASYNC_OBJS@ \
cache_cf.o \
+ CacheDigest.o \
cbdata.o \
client_db.o \
client_side.o \
store.o \
store_clean.o \
store_client.o \
+ store_digest.o \
store_dir.o \
store_key_md5.o \
store_log.o \
/*
- * $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
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)) {
enum {
NEIGHBOR_PROXY_ONLY,
NEIGHBOR_NO_QUERY,
+ NEIGHBOR_NO_DIGEST,
NEIGHBOR_DEFAULT_PARENT,
NEIGHBOR_ROUNDROBIN,
NEIGHBOR_MCAST_RESPONDER,
/*
- * $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 */
extern const String StringNull; /* { 0, 0, NULL } */
extern int hot_obj_count; /* 0 */
extern int _db_level;
+extern CacheDigest *store_digest; /* NULL */
/*
- * $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
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))
*/
extern EVH storeDirClean;
+/* store_digest.c */
+extern void storeDigestInit();
+extern void storeDigestRebuild();
+extern void storeDigestReport();
+
+
/*
* store_dir.c
*/
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
/*
- * $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
*
#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 */
/*
- * $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/
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);
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
}
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);
}
storeInitHashValues();
store_table = hash_create(storeKeyHashCmp,
store_hash_buckets, storeKeyHashHash);
+ storeDigestInit();
storeLogOpen();
if (storeVerifyCacheDirs() < 0) {
xstrncpy(tmp_error_buf,
hashFreeItems(store_table, destroy_StoreEntry);
hashFreeMemory(store_table);
store_table = NULL;
+ if (store_digest)
+ cacheDigestDestroy(store_digest);
+ store_digest = NULL;
}
int
--- /dev/null
+/*
+ * $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");
+ }
+}
+
+/*
+ * $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
/* 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;
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;
}
/*
- * $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
*
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