Commit a8858f67 authored by Chris McDonough's avatar Chris McDonough

Small refactoring and bug caught in computation of "plast" which had the...

Small refactoring and bug caught in computation of "plast" which had the potential to cause slowness.
parent 887450dc
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
""" """
Transient Object Container Class ('timeslice'-based design). Transient Object Container Class ('timeslice'-based design).
$Id: Transience.py,v 1.31 2003/01/09 16:38:03 chrism Exp $ $Id: Transience.py,v 1.32 2003/01/21 07:55:22 chrism Exp $
""" """
__version__='$Revision: 1.31 $'[11:-2] __version__='$Revision: 1.32 $'[11:-2]
import Globals import Globals
from Globals import HTMLFile from Globals import HTMLFile
...@@ -449,15 +449,20 @@ class TransientObjectContainer(SimpleItem): ...@@ -449,15 +449,20 @@ class TransientObjectContainer(SimpleItem):
if self._data is None: if self._data is None:
self._upgrade() 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 == the current timeslice
pnow = self._getCurrentTimeslice() 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 == the last timeslice under which we did housekeeping
plast = self._last_timeslice() 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): if not data.has_key(pnow):
# we were asleep a little too long, we don't even have a # we were asleep a little too long, we don't even have a
...@@ -477,31 +482,13 @@ class TransientObjectContainer(SimpleItem): ...@@ -477,31 +482,13 @@ class TransientObjectContainer(SimpleItem):
# anything. # anything.
DEBUG and TLOG('_getCurrentBucket: new timeslice (pnow) %s' % pnow) 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 == the last timeslice integer kept by _data as a key.
pmax = data.maxKey() 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 # t_slices == this TOC's timeout expressed in slices
# (fewest number of timeslices that's >= t_secs) # (fewest number of timeslices that's >= t_secs)
t_slices = self._timeout_slices 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 # deindex_next == the timeslice of the bucket we need to start
# deindexing from # deindexing from
deindex_next = self._deindex_next() deindex_next = self._deindex_next()
...@@ -533,7 +520,7 @@ class TransientObjectContainer(SimpleItem): ...@@ -533,7 +520,7 @@ class TransientObjectContainer(SimpleItem):
# slices_since == the number of slices elapsed since the # slices_since == the number of slices elapsed since the
# timeslice implied by k # 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 # if the number of slices since 'k' is less than the number of
# slices that make up the timeout, break out of this loop. # slices that make up the timeout, break out of this loop.
...@@ -574,16 +561,28 @@ class TransientObjectContainer(SimpleItem): ...@@ -574,16 +561,28 @@ class TransientObjectContainer(SimpleItem):
deindex_next = k+period deindex_next = k+period
self._deindex_next.set(deindex_next) self._deindex_next.set(deindex_next)
# available_spares == the number of "spare" ("clean", "future") # housekeep_elected indicates that this thread was elected to do
# buckets that exist in "_data" # housekeeping. We set it off initially and only set it true if
available_spares = (pmax-pnow) / period # we "win the roll". The "roll" is necessary to avoid a conflict
DEBUG and TLOG( # scenario where more than one thread tries to do housekeeping at
'_getCurrentBucket: available_spares %s' % available_spares # 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 we were elected to do housekeeping, do it now.
if housekeep_elected: 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 == the last bucket we want to destroy
delete_end = deindex_next - period delete_end = deindex_next - period
......
...@@ -96,9 +96,9 @@ class TestNotifications(TestBase): ...@@ -96,9 +96,9 @@ class TestNotifications(TestBase):
timeout = self.timeout * 60 timeout = self.timeout * 60
fauxtime.sleep(timeout + (timeout * .75)) fauxtime.sleep(timeout + (timeout * .75))
sdo1 = self.app.sm.get('TempObject') sdo1 = self.app.sm.get('TempObject')
for x in range(1, 100): # force the sdm to do housekeeping
# force the sdm to do housekeeping self.app.sm._housekeep(self.app.sm._deindex_next() -
self.app.sm._getCurrentBucket() self.app.sm._period)
now = fauxtime.time() now = fauxtime.time()
k = sdo.get('endtime') k = sdo.get('endtime')
assert (type(k) == type(now)), type(k) assert (type(k) == type(now)), type(k)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment