/*
- * $Id: store_heap_replacement.cc,v 1.10 2002/10/15 08:03:36 robertc Exp $
+ * $Id$
*
* DEBUG: section 20 Storage Manager Heap-based replacement
* AUTHOR: John Dilley
* 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., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
/*
* The code in this file is Copyrighted (C) 1999 by Hewlett Packard.
- *
+ *
*
* For a description of these cache replacement policies see --
* http://www.hpl.hp.com/techreports/1999/HPL-1999-69.html
#include "heap.h"
#include "store_heap_replacement.h"
#include "Store.h"
+#include "MemObject.h"
+#include "SquidTime.h"
+
+#if HAVE_MATH_H
+#include <math.h>
+#endif
/*
* Key generation function to implement the LFU-DA policy (Least
* in cache regardless of size. Achieves lower hit rate than GDS
* because there are more large objects in cache (so less room for
* smaller popular objects).
- *
+ *
* This version implements a tie-breaker based upon recency
* (e->lastref): for objects that have the same reference count
* the most recent object wins (gets a higher key value).
StoreEntry *e = (StoreEntry *)entry;
heap_key key;
double tie;
+
if (e->lastref <= 0)
- tie = 0.0;
+ tie = 0.0;
else if (squid_curtime <= e->lastref)
- tie = 0.0;
+ tie = 0.0;
else
- tie = 1.0 - exp((double) (e->lastref - squid_curtime) / 86400.0);
+ tie = 1.0 - exp((double) (e->lastref - squid_curtime) / 86400.0);
+
key = heap_age + (double) e->refcount - tie;
- debug(81, 3) ("HeapKeyGen_StoreEntry_LFUDA: %s refcnt=%d lastref=%ld heap_age=%f tie=%f -> %f\n",
- e->getMD5Text(), (int)e->refcount, e->lastref, heap_age, tie, key);
+
+ debugs(81, 3, "HeapKeyGen_StoreEntry_LFUDA: " << e->getMD5Text() <<
+ " refcnt=" << e->refcount << " lastref=" << e->lastref <<
+ " heap_age=" << heap_age << " tie=" << tie << " -> " << key);
+
if (e->mem_obj && e->mem_obj->url)
- debug(81, 3) ("HeapKeyGen_StoreEntry_LFUDA: url=%s\n",
- e->mem_obj->url);
+ debugs(81, 3, "HeapKeyGen_StoreEntry_LFUDA: url=" << e->mem_obj->url);
+
return (double) key;
}
-
/*
* Key generation function to implement the GDS-Frequency policy.
* Similar to Greedy Dual-Size Hits policy, but adds aging of
* keeping more small, popular objects in cache. Achieves lower
* byte hit rate than LFUDA because there are fewer large objects
* in cache.
- *
+ *
* This version implements a tie-breaker based upon recency
* (e->lastref): for objects that have the same reference count
* the most recent object wins (gets a higher key value).
double size = e->swap_file_sz ? (double) e->swap_file_sz : 1.0;
double tie = (e->lastref > 1) ? (1.0 / e->lastref) : 1.0;
key = heap_age + ((double) e->refcount / size) - tie;
- debug(81, 3) ("HeapKeyGen_StoreEntry_GDSF: %s size=%f refcnt=%d lastref=%ld heap_age=%f tie=%f -> %f\n",
- e->getMD5Text(), size, (int)e->refcount, e->lastref, heap_age, tie, key);
+ debugs(81, 3, "HeapKeyGen_StoreEntry_GDSF: " << e->getMD5Text() <<
+ " size=" << size << " refcnt=" << e->refcount << " lastref=" <<
+ e->lastref << " heap_age=" << heap_age << " tie=" << tie <<
+ " -> " << key);
+
if (e->mem_obj && e->mem_obj->url)
- debug(81, 3) ("HeapKeyGen_StoreEntry_GDSF: url=%s\n",
- e->mem_obj->url);
+ debugs(81, 3, "HeapKeyGen_StoreEntry_GDSF: url=" << e->mem_obj->url);
+
return key;
}
-/*
+/*
* Key generation function to implement the LRU policy. Normally
* one would not do this with a heap -- use the linked list instead.
* For testing and performance characterization it was useful.
HeapKeyGen_StoreEntry_LRU(void *entry, double heap_age)
{
StoreEntry *e = (StoreEntry *)entry;
- debug(81, 3) ("HeapKeyGen_StoreEntry_LRU: %s heap_age=%f lastref=%f\n",
- e->getMD5Text(), heap_age, (double) e->lastref);
+ debugs(81, 3, "HeapKeyGen_StoreEntry_LRU: " <<
+ e->getMD5Text() << " heap_age=" << heap_age <<
+ " lastref=" << (double) e->lastref );
+
if (e->mem_obj && e->mem_obj->url)
- debug(81, 3) ("HeapKeyGen_StoreEntry_LRU: url=%s\n",
- e->mem_obj->url);
+ debugs(81, 3, "HeapKeyGen_StoreEntry_LRU: url=" << e->mem_obj->url);
+
return (heap_key) e->lastref;
}