[Zodb-checkins] CVS: ZODB3/ZEO - simul.py:1.12.8.2.18.6

Jeremy Hylton cvs-admin at zope.org
Wed Dec 3 00:39:59 EST 2003


Update of /cvs-repository/ZODB3/ZEO
In directory cvs.zope.org:/tmp/cvs-serv18687

Modified Files:
      Tag: Zope-2_6-branch
	simul.py 
Log Message:
Implement the OracleSimulation by scanning the file in advance.
Also fix the formatting of the extra stats.


=== ZODB3/ZEO/simul.py 1.12.8.2.18.5 => 1.12.8.2.18.6 ===
--- ZODB3/ZEO/simul.py:1.12.8.2.18.5	Wed Dec  3 00:25:18 2003
+++ ZODB3/ZEO/simul.py	Wed Dec  3 00:39:58 2003
@@ -106,6 +106,8 @@
     # Create simulation object
     if omicron is not None:
         sim = simclass(cachelimit, omicron)
+    elif simclass is OracleSimulation:
+        sim = simclass(cachelimit, filename)
     else:
         sim = simclass(cachelimit)
 
@@ -221,7 +223,7 @@
     def inval(self, oid):
         pass
 
-    format = "%12s %9s %8s %8s %6s %6s %6s"
+    format = "%12s %9s %8s %8s %6s %6s %7s"
 
     # Subclass should override extraname to name known instance variables;
     # if extraname is 'foo', both self.foo and self.total_foo must exist:
@@ -629,7 +631,58 @@
     # cache with a list of objects that will be accessed more than
     # once and only cache those objects.
 
-    pass
+    def __init__(self, cachelimit, filename):
+        LRUCacheSimulation.__init__(self, cachelimit)
+        self.count = {}
+        self.scan(filename)
+
+    def load(self, oid, size):
+        node = self.cache.get(oid)
+        if node is not None:
+            self.hits += 1
+            self.total_hits += 1
+            node.linkbefore(self.head)
+        else:
+            if oid in self.count:
+                self.write(oid, size)
+
+    def scan(self, filename):
+        # scan the file in advance to figure out which objects will
+        # be referenced more than once.
+        f = open(filename, "rb")
+        struct_unpack = struct.unpack
+        f_read = f.read
+        offset = 0
+        while 1:
+            # Read a record and decode it
+            r = f_read(8)
+            if len(r) < 8:
+                break
+            offset += 8
+            ts, code = struct_unpack(">ii", r)
+            if ts == 0:
+                # Must be a misaligned record caused by a crash
+                ##print "Skipping 8 bytes at offset", offset-8
+                continue
+            r = f_read(16)
+            if len(r) < 16:
+                break
+            offset += 16
+            oid, serial = struct_unpack(">8s8s", r)
+            if code & 0x70 == 0x20:
+                # only look at loads
+                self.count[oid] = self.count.get(oid, 0) + 1
+
+        all = len(self.count)
+
+        # Now remove everything with count == 1
+        once = [oid for oid, count in self.count.iteritems()
+                if count == 1]
+        for oid in once:
+            del self.count[oid]
+
+        print "Scanned file, %d unique oids, %d repeats" % (
+            all, len(self.count))
 
 class CircularCacheSimulation(Simulation):
 




More information about the Zodb-checkins mailing list