/*
- * $Id: CacheDigest.cc,v 1.3 1998/04/01 00:14:00 rousskov Exp $
+ * $Id: CacheDigest.cc,v 1.4 1998/04/01 06:22:03 rousskov Exp $
*
* DEBUG: section ?? Cache Digest
* AUTHOR: Alex Rousskov
CacheDigest *clone;
assert(cd);
clone = cacheDigestCreate(cd->capacity);
+ clone->count = cd->count;
xmemcpy(clone->mask, cd->mask, cd->mask_size);
return clone;
}
-void
-cacheDigestAdd(CacheDigest * cd, const cache_key * key)
-{
- assert(cd && key);
- /* hash */
- cacheDigestHashKey(cd->capacity * BitsPerEntry, key);
- /* turn on corresponding bits */
- CBIT_SET(cd->mask, hashed_keys[0]);
- CBIT_SET(cd->mask, hashed_keys[1]);
- CBIT_SET(cd->mask, hashed_keys[2]);
- CBIT_SET(cd->mask, hashed_keys[3]);
- cd->count++;
-}
-
/* returns true if the key belongs to the digest */
int
cacheDigestTest(const CacheDigest * cd, const cache_key * key)
CBIT_TEST(cd->mask, hashed_keys[3]);
}
+void
+cacheDigestAdd(CacheDigest * cd, const cache_key * key)
+{
+ assert(cd && key);
+ /* hash */
+ cacheDigestHashKey(cd->capacity * BitsPerEntry, key);
+ /* turn on corresponding bits */
+ CBIT_SET(cd->mask, hashed_keys[0]);
+ CBIT_SET(cd->mask, hashed_keys[1]);
+ CBIT_SET(cd->mask, hashed_keys[2]);
+ CBIT_SET(cd->mask, hashed_keys[3]);
+ cd->count++;
+}
+
void
cacheDigestDel(CacheDigest * cd, const cache_key * key)
{
/* we do not support deletions from the digest */
}
+/* returns mask utilization parameters */
+double
+cacheDigestUtil(const CacheDigest * cd, int *bit_cnt_p, int *on_cnt_p)
+{
+ const int bit_count = cd->capacity * BitsPerEntry;
+ int pos = bit_count;
+ int on_count = 0;
+ while (pos-- > 0) {
+ if (CBIT_TEST(cd->mask, pos))
+ on_count++;
+ }
+ if (bit_cnt_p)
+ *bit_cnt_p = bit_count;
+ if (on_cnt_p)
+ *on_cnt_p = on_count;
+ return xpercent(on_count, bit_count);
+}
static void
cacheDigestHashKey(int bit_count, const char *key)
/*
- * $Id: test_cache_digest.cc,v 1.8 1998/04/01 05:02:21 rousskov Exp $
+ * $Id: test_cache_digest.cc,v 1.9 1998/04/01 06:22:04 rousskov Exp $
*
* AUTHOR: Alex Rousskov
*
Cache *peer;
CacheQueryStats qstats;
int count; /* #currently cached entries */
+ int req_count; /* #requests to this cache */
int bad_add_count; /* #duplicate adds */
int bad_del_count; /* #dels with no prior add */
};
static void
cacheQueryReport(Cache * cache, CacheQueryStats *stats)
{
- fprintf(stdout, "%s: icp: %d\n", cache->name, stats->query_count);
+ fprintf(stdout, "%s: peer queries: %d (%d%%)\n",
+ cache->name,
+ stats->query_count, xpercentInt(stats->query_count, cache->req_count)
+ );
fprintf(stdout, "%s: t-hit: %d (%d%%) t-miss: %d (%d%%) t-*: %d (%d%%)\n",
cache->name,
stats->true_hit_count, xpercentInt(stats->true_hit_count, stats->query_count),
);
}
+static void
+cacheReport(Cache * cache)
+{
+ fprintf(stdout, "%s: entries: %d reqs: %d bad-add: %d bad-del: %d\n",
+ 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 cap: %d util: %d%% size: %d b\n",
+ cache->name,
+ cache->digest->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
cacheFetch(Cache *cache, const RawAccessLogEntry *e)
{
assert(e);
+ cache->req_count++;
if (e->use_icp)
cacheQueryPeer(cache, e->key);
}
strcmp(hier, "PASSTHROUGH_PARENT") &&
strcmp(hier, "SSL_PARENT_MISS") &&
strcmp(hier, "DEFAULT_PARENT");
- if (!entry->use_icp)
- return frMore;
memcpy(entry->key, storeKeyPublic(url, method_id), sizeof(entry->key));
/*fprintf(stdout, "%s:%d: %s %s %s %s\n",
fname, count, method, storeKeyText(entry->key), url, hier); */
fis[0] = fileIteratorCreate(argv[1], accessLogReader);
for (i = 2; i < argc; ++i) {
fis[i-1] = fileIteratorCreate(argv[i], swapStateReader);
+ if (!fis[i-1]) return -2;
}
/* read prefix to get start-up contents of the peer cache */
ready_time = -1;
if (next_i == 0)
cacheFetch(us, fis[next_i]->entry);
else
- cacheUpdateStore(them, fis[next_i]->entry, 0);
+ cacheUpdateStore(them, fis[next_i]->entry, 1);
fileIteratorAdvance(fis[next_i]);
}
} while (active_fi_count);
/* report */
+ cacheReport(them);
+ cacheReport(us);
cacheQueryReport(us, &us->qstats);
/* clean */