Created
July 11, 2011 22:54
-
-
Save bnyeggen/1077002 to your computer and use it in GitHub Desktop.
A RAID MTBF calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#redundancy is the max number of survivable failures, so eg 1 for RAID5 | |
#mtbf_array is an array of either actual mean-time-between-failures, or a nested RAID array | |
# RAID([100]*7,2) #7 disk RAID 6 | |
# RAID([RAID([100]*3,1),RAID([1000]*3,1)],0) # RAID 50, 2 arrays of 3 | |
# RAID([100,100,50,50],1) #RAID 5 with varying reliabilities | |
from random import random | |
class RAID(object): | |
def __init__(self,mtbf_ary,redundancy): | |
self.mtbf_ary=mtbf_ary | |
self.redundancy=redundancy | |
self.mtbf_cache=False | |
return | |
def mtbf(self,sims=10000,recalc=False): | |
if self.mtbf_cache and not recalc: return self.mtbf_cache | |
failtimes=[None]*sims | |
failrates=[None]*len(self.mtbf_ary) | |
for idx,item in enumerate(self.mtbf_ary): | |
if type(item) is float or type(item) is int: | |
failrates[idx]=1.0 / float(item) | |
if isinstance(item,RAID): | |
failrates[idx]=1.0 / item.mtbf(sims) | |
for i in range(sims): | |
trials=0 | |
failcount=0 | |
alive=[True]*len(self.mtbf_ary) | |
while failcount<=self.redundancy: | |
trials+=1 | |
for idx,item in enumerate(self.mtbf_ary): | |
if random()<failrates[idx] and alive[idx]: | |
failcount+=1 | |
alive[idx]=False | |
failtimes[i]=trials | |
self.mtbf_cache=float(sum(failtimes)) / len(failtimes) | |
return self.mtbf_cache #mean time to array failure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment