[Zope-Checkins] CVS: Zope/lib/python/Products/Transience - Transience.py:1.28.6.4
Chris McDonough
chrism@zope.com
Tue, 21 Jan 2003 02:57:23 -0500
Update of /cvs-repository/Zope/lib/python/Products/Transience
In directory cvs.zope.org:/tmp/cvs-serv24086
Modified Files:
Tag: Zope-2_6-branch
Transience.py
Log Message:
Small refactoring and bug fixed which had the potential to cause slowness.
=== Zope/lib/python/Products/Transience/Transience.py 1.28.6.3 => 1.28.6.4 ===
--- Zope/lib/python/Products/Transience/Transience.py:1.28.6.3 Thu Jan 9 11:41:41 2003
+++ Zope/lib/python/Products/Transience/Transience.py Tue Jan 21 02:56:51 2003
@@ -449,15 +449,20 @@
if self._data is None:
self._upgrade()
+ # data is the mapping from timeslice to bucket
+ data = self._data
+
+ # period == number of seconds in a slice
+ period = self._period
+
# pnow == the current timeslice
pnow = self._getCurrentTimeslice()
+ # pprev = the true previous timeslice in relation to pnow
+ pprev = pnow - period
+
# plast == the last timeslice under which we did housekeeping
plast = self._last_timeslice()
- plast = pnow - self._period
-
- # data is the mapping from timeslice to bucket
- data = self._data
if not data.has_key(pnow):
# we were asleep a little too long, we don't even have a
@@ -477,31 +482,13 @@
# anything.
DEBUG and TLOG('_getCurrentBucket: new timeslice (pnow) %s' % pnow)
- # period == number of seconds in a slice
- period = self._period
-
# pmax == the last timeslice integer kept by _data as a key.
pmax = data.maxKey()
- # housekeep_elected indicates that this thread was elected to do
- # housekeeping. We set it off initially and only set it true if
- # we "win the roll". The "roll" is necessary to avoid a conflict
- # scenario where more than one thread tries to do housekeeping at
- # the same time.
- housekeep_elected = 0
-
- # We ask this thread to "roll the dice." If it wins, it gets
- # elected to do housekeeping
- housekeep_elected = self._roll(pnow, pmax)
- housekeep_elected and DEBUG and TLOG('housekeep elected')
-
# t_slices == this TOC's timeout expressed in slices
# (fewest number of timeslices that's >= t_secs)
t_slices = self._timeout_slices
- # pprev = the truly previous timeslice in relation to pnow
- pprev = pnow - period
-
# deindex_next == the timeslice of the bucket we need to start
# deindexing from
deindex_next = self._deindex_next()
@@ -533,7 +520,7 @@
# slices_since == the number of slices elapsed since the
# timeslice implied by k
- slices_since = pthen / period
+ slices_since = pthen / self._period
# if the number of slices since 'k' is less than the number of
# slices that make up the timeout, break out of this loop.
@@ -574,15 +561,27 @@
deindex_next = k+period
self._deindex_next.set(deindex_next)
- # available_spares == the number of "spare" ("clean", "future")
- # buckets that exist in "_data"
- available_spares = (pmax-pnow) / period
- DEBUG and TLOG(
- '_getCurrentBucket: available_spares %s' % available_spares
- )
+ # housekeep_elected indicates that this thread was elected to do
+ # housekeeping. We set it off initially and only set it true if
+ # we "win the roll". The "roll" is necessary to avoid a conflict
+ # scenario where more than one thread tries to do housekeeping at
+ # the same time.
+ housekeep_elected = 0
+
+ # We ask this thread to "roll the dice." If it wins, it gets
+ # elected to do housekeeping
+ housekeep_elected = self._roll(pnow, pmax)
+ housekeep_elected and DEBUG and TLOG('housekeep elected')
# if we were elected to do housekeeping, do it now.
if housekeep_elected:
+
+ # available_spares == the number of "spare" ("clean", "future")
+ # buckets that exist in "_data"
+ available_spares = (pmax-pnow) / period
+ DEBUG and TLOG(
+ '_getCurrentBucket: available_spares %s' % available_spares
+ )
# delete_end == the last bucket we want to destroy
delete_end = deindex_next - period