[Zodb-checkins] CVS: ZODB3/ZEO - simul.py:1.12
Guido van Rossum
guido@python.org
Tue, 17 Sep 2002 12:12:46 -0400
Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv18367
Modified Files:
simul.py
Log Message:
Add -y, simulating a variation of the existing ZEO cache which copies
hits found in the non-current file into the current file.
For the 40-hour trace starting on Sept 4 at 6pm, this increases the
hit rate from 83.2% to 87.0% (IOW a decrease in miss rate from 16.8%
to 13%):
ZEOCacheSimulation, cache size 200,000,000 bytes
START TIME DURATION LOADS HITS INVALS WRITES FLIPS HITRATE
Sep 4 18:00 40:36:34 1420070 1181176 16198 10014 15 83.2%
AltZEOCacheSimulation, cache size 200,000,000 bytes
START TIME DURATION LOADS HITS INVALS WRITES FLIPS HITRATE
Sep 4 18:00 40:36:34 1420070 1235770 15384 10014 25 87.0%
=== ZODB3/ZEO/simul.py 1.11 => 1.12 ===
--- ZODB3/ZEO/simul.py:1.11 Tue Sep 10 13:53:28 2002
+++ ZODB3/ZEO/simul.py Tue Sep 17 12:12:46 2002
@@ -14,12 +14,13 @@
##############################################################################
"""Cache simulation.
-Usage: simul.py [-bflz] [-s size] tracefile
+Usage: simul.py [-bflyz] [-s size] tracefile
-Use one of -b, -f, -l or -z select the cache simulator:
+Use one of -b, -f, -l, -y or -z select the cache simulator:
-b: buddy system allocator
-f: simple free list allocator
-l: idealized LRU (no allocator)
+-y: variation on the existing ZEO cache that copies to current file
-z: existing ZEO cache (default)
Options:
@@ -43,7 +44,7 @@
cachelimit = 20*MB
simclass = ZEOCacheSimulation
try:
- opts, args = getopt.getopt(sys.argv[1:], "bflzs:")
+ opts, args = getopt.getopt(sys.argv[1:], "bflyzs:")
except getopt.error, msg:
usage(msg)
return 2
@@ -54,6 +55,8 @@
simclass = SimpleCacheSimulation
if o == '-l':
simclass = LRUCacheSimulation
+ if o == '-y':
+ simclass = AltZEOCacheSimulation
if o == '-z':
simclass = ZEOCacheSimulation
if o == '-s':
@@ -281,6 +284,32 @@
self.invals += 1
self.total_invals += 1
del self.fileoids[1 - self.current][oid]
+
+class AltZEOCacheSimulation(ZEOCacheSimulation):
+
+ """A variation of the ZEO cache that copies to the current file.
+
+ When a hit is found in the non-current cache file, it is copied to
+ the current cache file. Exception: when the copy would cause a
+ cache flip, we don't copy (this is part laziness, part concern
+ over causing extraneous flips).
+ """
+
+ def load(self, oid, size):
+ if self.fileoids[self.current].get(oid):
+ self.hits += 1
+ self.total_hits += 1
+ elif self.fileoids[1 - self.current].get(oid):
+ self.hits += 1
+ self.total_hits += 1
+ # Simulate a write, unless it would cause a flip
+ size = size + 31 - 127
+ if self.filesize[self.current] + size <= self.cachelimit / 2:
+ self.filesize[self.current] += size
+ self.fileoids[self.current][oid] = 1
+ del self.fileoids[1 - self.current][oid]
+ else:
+ self.write(oid, size)
class LRUCacheSimulation(Simulation):