mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-21 16:39:38 +00:00
reliability: switch to NumPy, since Numeric is deprecated
This commit is contained in:
@ -2,23 +2,12 @@
|
|||||||
|
|
||||||
import math
|
import math
|
||||||
from allmydata.util import statistics
|
from allmydata.util import statistics
|
||||||
import Numeric
|
from numpy import array
|
||||||
from Numeric import array, matrixmultiply as mm
|
|
||||||
|
|
||||||
DAY=24*60*60
|
DAY=24*60*60
|
||||||
MONTH=31*DAY
|
MONTH=31*DAY
|
||||||
YEAR=365*DAY
|
YEAR=365*DAY
|
||||||
|
|
||||||
def my_dot(v1, v2):
|
|
||||||
#print v1.shape, v2.shape
|
|
||||||
#assert len(v1.shape) == 2
|
|
||||||
#assert v1.shape[0] == 1
|
|
||||||
#assert len(v2.shape) == 2
|
|
||||||
#assert v2.shape[0] == 1
|
|
||||||
#assert v1.shape[1] == v2.shape[1]
|
|
||||||
#for i in range(v1.shape[1]):
|
|
||||||
return Numeric.sum(Numeric.sum(v1*v2))
|
|
||||||
|
|
||||||
class ReliabilityModel:
|
class ReliabilityModel:
|
||||||
"""Generate a model of system-wide reliability, given several input
|
"""Generate a model of system-wide reliability, given several input
|
||||||
parameters.
|
parameters.
|
||||||
@ -85,9 +74,9 @@ class ReliabilityModel:
|
|||||||
|
|
||||||
#print "DECAY:", decay
|
#print "DECAY:", decay
|
||||||
#print "OLD-POST-REPAIR:", old_post_repair
|
#print "OLD-POST-REPAIR:", old_post_repair
|
||||||
#print "NEW-POST-REPAIR:", mm(decay, repair)
|
#print "NEW-POST-REPAIR:", decay * repair
|
||||||
#print "REPAIR:", repair
|
#print "REPAIR:", repair
|
||||||
#print "DIFF:", (old_post_repair - mm(decay, repair))
|
#print "DIFF:", (old_post_repair - decay * repair)
|
||||||
|
|
||||||
START = array([[0]*N + [1]])
|
START = array([[0]*N + [1]])
|
||||||
ALIVE = array([[0]*k + [1]*(1+N-k)])
|
ALIVE = array([[0]*k + [1]*(1+N-k)])
|
||||||
@ -112,24 +101,24 @@ class ReliabilityModel:
|
|||||||
report = ReliabilityReport()
|
report = ReliabilityReport()
|
||||||
|
|
||||||
for t in range(0, report_span+delta, delta):
|
for t in range(0, report_span+delta, delta):
|
||||||
unmaintained_state = mm(unmaintained_state, decay)
|
unmaintained_state = unmaintained_state * decay
|
||||||
maintained_state = mm(maintained_state, decay)
|
maintained_state = maintained_state * decay
|
||||||
if (t-last_check) > check_period:
|
if (t-last_check) > check_period:
|
||||||
last_check = t
|
last_check = t
|
||||||
# we do a check-and-repair this frequently
|
# we do a check-and-repair this frequently
|
||||||
need_repair = my_dot(maintained_state, REPAIRp)
|
need_repair = (maintained_state * REPAIRp).sum()
|
||||||
|
|
||||||
P_repaired_last_check_period = need_repair
|
P_repaired_last_check_period = need_repair
|
||||||
new_shares = my_dot(maintained_state, REPAIR_newshares)
|
new_shares = (maintained_state * REPAIR_newshares).sum()
|
||||||
needed_repairs.append(need_repair)
|
needed_repairs.append(need_repair)
|
||||||
needed_new_shares.append(new_shares)
|
needed_new_shares.append(new_shares)
|
||||||
|
|
||||||
maintained_state = mm(maintained_state, repair)
|
maintained_state = maintained_state * repair
|
||||||
|
|
||||||
if (t-last_report) > report_period:
|
if (t-last_report) > report_period:
|
||||||
last_report = t
|
last_report = t
|
||||||
P_dead_unmaintained = my_dot(unmaintained_state, DEAD)
|
P_dead_unmaintained = (unmaintained_state * DEAD).sum()
|
||||||
P_dead_maintained = my_dot(maintained_state, DEAD)
|
P_dead_maintained = (maintained_state * DEAD).sum()
|
||||||
cumulative_number_of_repairs = sum(needed_repairs)
|
cumulative_number_of_repairs = sum(needed_repairs)
|
||||||
cumulative_number_of_new_shares = sum(needed_new_shares)
|
cumulative_number_of_new_shares = sum(needed_new_shares)
|
||||||
report.add_sample(t, unmaintained_state, maintained_state,
|
report.add_sample(t, unmaintained_state, maintained_state,
|
||||||
@ -139,8 +128,8 @@ class ReliabilityModel:
|
|||||||
P_dead_unmaintained, P_dead_maintained)
|
P_dead_unmaintained, P_dead_maintained)
|
||||||
|
|
||||||
# record one more sample at the end of the run
|
# record one more sample at the end of the run
|
||||||
P_dead_unmaintained = my_dot(unmaintained_state, DEAD)
|
P_dead_unmaintained = (unmaintained_state * DEAD).sum()
|
||||||
P_dead_maintained = my_dot(maintained_state, DEAD)
|
P_dead_maintained = (maintained_state * DEAD).sum()
|
||||||
cumulative_number_of_repairs = sum(needed_repairs)
|
cumulative_number_of_repairs = sum(needed_repairs)
|
||||||
cumulative_number_of_new_shares = sum(needed_new_shares)
|
cumulative_number_of_new_shares = sum(needed_new_shares)
|
||||||
report.add_sample(t, unmaintained_state, maintained_state,
|
report.add_sample(t, unmaintained_state, maintained_state,
|
||||||
|
@ -5,7 +5,7 @@ ReliabilityModel = None
|
|||||||
try:
|
try:
|
||||||
from allmydata.reliability import ReliabilityModel
|
from allmydata.reliability import ReliabilityModel
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass # might not be importable, since it needs Numeric
|
pass # might not be importable, since it needs NumPy
|
||||||
|
|
||||||
from nevow import inevow
|
from nevow import inevow
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
@ -70,7 +70,7 @@ YEAR=365*DAY
|
|||||||
class Reliability(unittest.TestCase):
|
class Reliability(unittest.TestCase):
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
if ReliabilityModel is None:
|
if ReliabilityModel is None:
|
||||||
raise unittest.SkipTest("reliability model requires Numeric")
|
raise unittest.SkipTest("reliability model requires NumPy")
|
||||||
r = ReliabilityModel.run(delta=100000,
|
r = ReliabilityModel.run(delta=100000,
|
||||||
report_period=3*MONTH,
|
report_period=3*MONTH,
|
||||||
report_span=5*YEAR)
|
report_span=5*YEAR)
|
||||||
|
@ -476,7 +476,7 @@ class Web(WebMixin, testutil.StallMixin, unittest.TestCase):
|
|||||||
from allmydata import reliability
|
from allmydata import reliability
|
||||||
_hush_pyflakes = reliability
|
_hush_pyflakes = reliability
|
||||||
except:
|
except:
|
||||||
raise unittest.SkipTest("reliability tool requires Numeric")
|
raise unittest.SkipTest("reliability tool requires NumPy")
|
||||||
|
|
||||||
d = self.GET("/reliability/")
|
d = self.GET("/reliability/")
|
||||||
def _check(res):
|
def _check(res):
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from nevow import rend, inevow, tags as T
|
from nevow import rend, inevow, tags as T
|
||||||
reliability = None # might not be usable
|
reliability = None # might not be usable
|
||||||
try:
|
try:
|
||||||
from allmydata import reliability # requires Numeric and PIL
|
from allmydata import reliability # requires NumPy
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
from allmydata.web.common import getxmlfile, get_arg
|
from allmydata.web.common import getxmlfile, get_arg
|
||||||
|
@ -122,7 +122,7 @@ class NoReliability(rend.Page):
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h2>"Reliability" page not available</h2>
|
<h2>"Reliability" page not available</h2>
|
||||||
<p>Please install the python "Numeric" module to enable this page.</p>
|
<p>Please install the python "NumPy" module to enable this page.</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
''')
|
''')
|
||||||
|
@ -10,7 +10,7 @@ from twisted.plugin import IPlugin
|
|||||||
# note that this .py file is *not* in a package: there is no __init__.py in
|
# note that this .py file is *not* in a package: there is no __init__.py in
|
||||||
# our parent directory. This is important, because otherwise ours would fight
|
# our parent directory. This is important, because otherwise ours would fight
|
||||||
# with Twisted's. When trial looks for plugins, it merely executes all the
|
# with Twisted's. When trial looks for plugins, it merely executes all the
|
||||||
# *.py files it finds in and twisted/plugins/ subdirectories of anything on
|
# *.py files it finds in any twisted/plugins/ subdirectories of anything on
|
||||||
# sys.path . The namespace that results from executing these .py files is
|
# sys.path . The namespace that results from executing these .py files is
|
||||||
# examined for instances which provide both IPlugin and the target interface
|
# examined for instances which provide both IPlugin and the target interface
|
||||||
# (in this case, trial is looking for IReporter instances). Each such
|
# (in this case, trial is looking for IReporter instances). Each such
|
||||||
|
Reference in New Issue
Block a user