You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2012/05/16 05:37:41 UTC
[2/2] git commit: TS-1238: Add optional to control seen filtering for
the RAM cache.
TS-1238: Add optional to control seen filtering for the RAM cache.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/453f1720
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/453f1720
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/453f1720
Branch: refs/heads/master
Commit: 453f1720a63c02b2a4edc63c2639d5a3f9f3bb0a
Parents: a2fd13c
Author: jplevyak@apache.org <jp...@apache.org>
Authored: Tue May 1 09:50:16 2012 -0700
Committer: John Plevyak <jp...@acm.org>
Committed: Tue May 15 20:32:01 2012 -0700
----------------------------------------------------------------------
iocore/cache/Cache.cc | 5 +++-
iocore/cache/P_CacheInternal.h | 1 +
iocore/cache/RamCacheCLFUS.cc | 10 +++++---
iocore/cache/RamCacheLRU.cc | 29 ++++++++++++++++++--------
iocore/cache/Store.cc | 2 +-
proxy/config/records.config.default.in | 6 +++++
6 files changed, 38 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/453f1720/iocore/cache/Cache.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index bcd5185..37ab0ef 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -57,6 +57,7 @@ int64_t cache_config_ram_cache_size = AUTO_SIZE_RAM_CACHE;
int cache_config_ram_cache_algorithm = 0;
int cache_config_ram_cache_compress = 0;
int cache_config_ram_cache_compress_percent = 90;
+int cache_config_ram_cache_use_seen_filter = 0;
int cache_config_http_max_alts = 3;
int cache_config_dir_sync_frequency = 60;
int cache_config_permit_pinning = 0;
@@ -2000,15 +2001,16 @@ CacheVC::handleRead(int event, Event *e)
return EVENT_CONT;
LramHit: {
+ f.doc_from_ram_cache = true;
io.aio_result = io.aiocb.aio_nbytes;
Doc *doc = (Doc*)buf->data();
if (cache_config_ram_cache_compress && doc->ftype == CACHE_FRAG_TYPE_HTTP && doc->hlen) {
SET_HANDLER(&CacheVC::handleReadDone);
- f.doc_from_ram_cache = true;
return EVENT_RETURN;
}
}
LmemHit:
+ f.doc_from_ram_cache = true;
io.aio_result = io.aiocb.aio_nbytes;
POP_HANDLER;
return EVENT_RETURN; // allow the caller to release the volume lock
@@ -2652,6 +2654,7 @@ ink_cache_init(ModuleVersion v)
IOCORE_EstablishStaticConfigInt32(cache_config_ram_cache_algorithm, "proxy.config.cache.ram_cache.algorithm");
IOCORE_EstablishStaticConfigInt32(cache_config_ram_cache_compress, "proxy.config.cache.ram_cache.compress");
IOCORE_EstablishStaticConfigInt32(cache_config_ram_cache_compress_percent, "proxy.config.cache.ram_cache.compress_percent");
+ IOCORE_EstablishStaticConfigInt32(cache_config_ram_cache_use_seen_filter, "proxy.config.cache.ram_cache.use_seen_filter");
IOCORE_EstablishStaticConfigInt32(cache_config_http_max_alts, "proxy.config.cache.limits.http.max_alts");
Debug("cache_init", "proxy.config.cache.limits.http.max_alts = %d", cache_config_http_max_alts);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/453f1720/iocore/cache/P_CacheInternal.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 075bb00..260edea 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -222,6 +222,7 @@ extern int cache_clustering_enabled;
extern int cache_config_agg_write_backlog;
extern int cache_config_ram_cache_compress;
extern int cache_config_ram_cache_compress_percent;
+extern int cache_config_ram_cache_use_seen_filter;
#ifdef HIT_EVACUATE
extern int cache_config_hit_evacuate_percent;
extern int cache_config_hit_evacuate_size_limit;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/453f1720/iocore/cache/RamCacheCLFUS.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/RamCacheCLFUS.cc b/iocore/cache/RamCacheCLFUS.cc
index 3ce7223..becf2fb 100644
--- a/iocore/cache/RamCacheCLFUS.cc
+++ b/iocore/cache/RamCacheCLFUS.cc
@@ -124,9 +124,11 @@ void RamCacheCLFUS::resize_hashtable() {
bucket = new_bucket;
nbuckets = anbuckets;
ats_free(seen);
- int size = bucket_sizes[ibuckets] * sizeof(uint16_t);
- seen = (uint16_t*)ats_malloc(size);
- memset(seen, 0, size);
+ if (cache_config_ram_cache_use_seen_filter) {
+ int size = bucket_sizes[ibuckets] * sizeof(uint16_t);
+ seen = (uint16_t*)ats_malloc(size);
+ memset(seen, 0, size);
+ }
}
void RamCacheCLFUS::init(int64_t abytes, Vol *avol) {
@@ -486,7 +488,7 @@ int RamCacheCLFUS::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool copy
if (!lru[1].head) // initial fill
if (bytes + size <= max_bytes)
goto Linsert;
- if (!e) {
+ if (!e && cache_config_ram_cache_use_seen_filter) {
uint32_t s = key->word(3) % bucket_sizes[ibuckets];
uint16_t k = key->word(3) >> 16;
uint16_t kk = seen[s];
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/453f1720/iocore/cache/RamCacheLRU.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/RamCacheLRU.cc b/iocore/cache/RamCacheLRU.cc
index 49f45b3..7562b12 100644
--- a/iocore/cache/RamCacheLRU.cc
+++ b/iocore/cache/RamCacheLRU.cc
@@ -83,11 +83,11 @@ void RamCacheLRU::resize_hashtable() {
bucket = new_bucket;
nbuckets = anbuckets;
ats_free(seen);
-
int size = bucket_sizes[ibuckets] * sizeof(uint16_t);
-
- seen = (uint16_t*)ats_malloc(size);
- memset(seen, 0, size);
+ if (cache_config_ram_cache_use_seen_filter) {
+ seen = (uint16_t*)ats_malloc(size);
+ memset(seen, 0, size);
+ }
}
void
@@ -136,17 +136,28 @@ RamCacheLRUEntry * RamCacheLRU::remove(RamCacheLRUEntry *e) {
return ret;
}
-// ignore 'len' and 'copy' since we don't touch the data
-int RamCacheLRU::put(INK_MD5 *key, IOBufferData *data, uint32_t, bool, uint32_t auxkey1, uint32_t auxkey2) {
+// ignore 'copy' since we don't touch the data
+int RamCacheLRU::put(INK_MD5 *key, IOBufferData *data, uint32_t len, bool, uint32_t auxkey1, uint32_t auxkey2) {
if (!max_bytes)
return 0;
uint32_t i = key->word(3) % nbuckets;
+ if (cache_config_ram_cache_use_seen_filter) {
+ uint16_t k = key->word(3) >> 16;
+ uint16_t kk = seen[i];
+ seen[i] = k;
+ if ((kk != (uint16_t)k)) {
+ DDebug("ram_cache", "put %X %d %d len %d UNSEEN", key->word(3), auxkey1, auxkey2, len);
+ return 0;
+ }
+ }
RamCacheLRUEntry *e = bucket[i].head;
while (e) {
if (e->key == *key) {
- if (e->auxkey1 == auxkey1 && e->auxkey2 == auxkey2)
- break;
- else { // discard when aux keys conflict
+ if (e->auxkey1 == auxkey1 && e->auxkey2 == auxkey2) {
+ lru.remove(e);
+ lru.enqueue(e);
+ return 1;
+ } else { // discard when aux keys conflict
e = remove(e);
continue;
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/453f1720/iocore/cache/Store.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Store.cc b/iocore/cache/Store.cc
index 423b613..1c05abe 100644
--- a/iocore/cache/Store.cc
+++ b/iocore/cache/Store.cc
@@ -701,7 +701,7 @@ Span::init(char *filename, int64_t size)
is_disk = 1;
adjusted_sec = hw_sector_size / 512;
Debug("cache_init", "Span::init - %s hw_sector_size=%d is_disk=%d adjusted_sec=%" PRId64,
- filename, hw_sector_size, is_disk,adjusted_sec);
+ filename, hw_sector_size, is_disk, adjusted_sec);
}
alignment = 0;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/453f1720/proxy/config/records.config.default.in
----------------------------------------------------------------------
diff --git a/proxy/config/records.config.default.in b/proxy/config/records.config.default.in
index 732f336..5bbf60d 100644
--- a/proxy/config/records.config.default.in
+++ b/proxy/config/records.config.default.in
@@ -321,6 +321,12 @@ CONFIG proxy.config.cache.ram_cache_cutoff INT 4194304
# 0 : Clocked Least Frequently Used by Size (CLFUS) w/optional compression
# 1 : LRU w/o optional compression - trivially simple
CONFIG proxy.config.cache.ram_cache.algorithm INT 0
+ # Filter inserts into the RAM cache to ensure that they have been seen at
+ # least once. For LRU, this provides scan resistance. Note that CLFUS
+ # already requires that a document have history before it is inserted, so
+ # for CLFUS, setting this option means that a document must be seen three
+ # times before it is added to the RAM cache.
+CONFIG proxy.config.cache.ram_cache.use_seen_filter INT 0
# Compress the content of the ram cache:
# 0 : no compression
# 1 : fastlz (extremely fast, relatively low compression)