[Zope-Checkins] CVS: Products/Transience - Transience.py:1.32.12.8.2.6

Chris McDonough chrism at plope.com
Mon Sep 13 12:27:42 EDT 2004


Update of /cvs-repository/Products/Transience
In directory cvs.zope.org:/tmp/cvs-serv2448

Modified Files:
      Tag: chrism-pre273-branch
	Transience.py 
Log Message:
Use a simpler indicator to tell if its OK to do garbage collection.


=== Products/Transience/Transience.py 1.32.12.8.2.5 => 1.32.12.8.2.6 ===
--- Products/Transience/Transience.py:1.32.12.8.2.5	Mon Sep 13 11:31:22 2004
+++ Products/Transience/Transience.py	Mon Sep 13 12:27:42 2004
@@ -711,6 +711,12 @@
         if not self._timeout_slices:
             return # dont do gc if there is no timeout
 
+        # give callers a good chance to do nothing (gc isn't as important
+        # as replentishment or finalization)
+        if not roll(0, 5, 'gc'):
+            DEBUG and TLOG('_gc: lost roll, doing nothing')
+            return
+
         if not self.gc_lock.acquire(0):
             DEBUG and TLOG('_gc: couldnt acquire lock')
             return
@@ -720,23 +726,16 @@
                 now = getCurrentTimeslice(self._period) # for unit tests
 
             last_gc = self._last_gc_timeslice()
-            gc_every = self._period * SPARE_BUCKETS
+            gc_every = self._period * round(SPARE_BUCKETS / 2.0)
 
             if (now - last_gc) < gc_every:
                 DEBUG and TLOG('_gc: gc attempt not yet required '
                                '( (%s - %s) < %s )' % (now, last_gc, gc_every))
                 return
-
-            if now <= 0:
-                DEBUG and TLOG('_gc: now is %s bailing' % now)
-                return
-
-            multiplier = now / float(now - last_gc)
-            high = int(round(multiplier * 2))
-
-            DEBUG and TLOG(
-                '_gc:  (%s -%s) > %s, gc possible' % (now, last_gc, gc_every))
-            if roll(0, high, 'gc'):
+            else:
+                DEBUG and TLOG(
+                    '_gc:  (%s -%s) > %s, gc invoked' % (now, last_gc,
+                                                          gc_every))
                 self._do_gc_work(now)
 
         finally:
@@ -752,14 +751,17 @@
 
         max_ts = self._last_finalized_timeslice()
 
-        DEBUG and TLOG('_gc: max_ts is %s' % max_ts)
+        DEBUG and TLOG('_do_gc_work: max_ts is %s' % max_ts)
+        to_gc = list(self._data.keys(None, max_ts))
+        DEBUG and TLOG('_do_gc_work: to_gc is: %s' % str(to_gc))
 
-        for key in list(self._data.keys(None, max_ts)):
+        for key in to_gc:
             assert(key <= max_ts)
             STRICT and _assert(self._data.has_key(key))
-            DEBUG and TLOG('deleting %s from _data' % key)
+            DEBUG and TLOG('_do_gc_work: deleting %s from _data' % key)
             del self._data[key]
 
+        DEBUG and TLOG('_do_gc_work: setting last_gc_timeslice to %s' % now)
         self._last_gc_timeslice.set(now)
 
     def notifyAdd(self, item):



More information about the Zope-Checkins mailing list