class HeuristicAvgMetaslab(object): def __init__(self, nmetaslabs): self.nmetaslabs = nmetaslabs self.pool = Pool(nmetaslabs) self.y_flushed = [] self.y_blocks = [] self.y_logs = [] def condition_satisfied(self): if self.pool.mss.nmetaslabs() >= self.pool.logs.nblocks: return True return False def flush_count(self): return int(self.nmetaslabs / (2 * self.pool.logs.nlogs())) def flush_count2(self): return int(self.nmetaslabs / self.pool.logs.nlogs()) def sync_cycle(self, incoming_blocks): if self.pool.syncing_txg == 0: all_metaslabs = self.pool.mss.ms_ordered_by_flushed self.pool.sync_new_changes(incoming_blocks, all_metaslabs) self.y_flushed.append(0) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) self.pool.sync_done() return nflushed = 0 while not self.condition_satisfied(): self.pool.flush_n_metaslabs(1) nflushed += 1 if self.pool.syncing_txg < 10: to_flush = max(self.flush_count() - nflushed, 0) if to_flush != 0: self.pool.flush_n_metaslabs(to_flush) nflushed += to_flush else: to_flush = max(self.flush_count2() - nflushed, 0) if to_flush != 0: self.pool.flush_n_metaslabs(to_flush) nflushed += to_flush ms_flushed_this_txg = self.pool.mss.ms_ordered_by_flushed[-nflushed:] self.pool.sync_new_changes(incoming_blocks, ms_flushed_this_txg) print "DBG -", self.pool.syncing_txg, "flushed", nflushed, "incoming", incoming_blocks, "nlogs", self.pool.logs.nlogs( ), self.pool.logs.nblocks self.pool.sync_done() self.y_flushed.append(nflushed) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) def simulate(self, y_incoming): for incoming in y_incoming: self.sync_cycle(incoming)
class HeuristicSummary(object): def __init__(self, nmetaslabs, blimit): self.nmetaslabs = nmetaslabs self.pool = Pool(nmetaslabs) self.y_flushed, self.y_blocks, self.y_logs = [], [], [] self.summary = Summary(self.pool) self.blimit = blimit #XXX: Hack global q q = int(blimit / 10) def printLogs(self): print "=== DBG - PRINT LOGS - START ===" for log in self.pool.logs.sms: print "[{}] - M {} - B {}".format(log.txg, len(log.metaslabs_flushed), log.blocks) print "=== DBG - PRINT LOGS - END ===" def condition_satisfied(self): if self.pool.mss.nmetaslabs() >= self.pool.logs.nblocks: return True return False def addGraphEntry(self, nflushed): self.y_flushed.append(nflushed) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) def initializeState(self, incoming): all_metaslabs = self.pool.mss.ms_ordered_by_flushed self.pool.sync_new_changes(incoming, all_metaslabs) self.summary.addData(self.pool.syncing_txg, len(all_metaslabs), incoming) self.summary.trimData(0, self.pool.logs.nblocks - incoming) print "DBG - TXG: {} - Flushed: {} ".format(self.pool.syncing_txg, len(all_metaslabs)) self.summary.printSummary() self.pool.sync_done() self.addGraphEntry(len(all_metaslabs)) def sync_cycle(self, incoming_blocks): if self.pool.syncing_txg == 0: self.initializeState(incoming_blocks) return nflushed = self.summary.adviceFlushing(incoming_blocks, self.blimit) self.pool.flush_n_metaslabs(nflushed) ms_flushed_this_txg = self.pool.mss.ms_ordered_by_flushed[-nflushed:] self.pool.sync_new_changes(incoming_blocks, ms_flushed_this_txg) self.summary.addData(self.pool.syncing_txg, nflushed, incoming_blocks) self.summary.trimData(nflushed, self.y_blocks[-1] -self.pool.logs.nblocks +incoming_blocks) print "DBG - TXG: {} - Flushed: {} ".format(self.pool.syncing_txg, nflushed) self.summary.printSummary() self.pool.sync_done() self.addGraphEntry(nflushed) def simulate(self, y_incoming): for incoming in y_incoming: self.sync_cycle(incoming)
class HeuristicIncoming(object): def __init__(self, nmetaslabs): self.nmetaslabs = nmetaslabs self.pool = Pool(nmetaslabs) self.y_flushed = [] self.y_blocks = [] self.y_logs = [] self.last_incoming = 0 def condition_satisfied(self): if self.pool.mss.nmetaslabs() >= self.pool.logs.nblocks: return True return False def sync_cycle(self, incoming_blocks): if self.pool.syncing_txg == 0: all_metaslabs = self.pool.mss.ms_ordered_by_flushed self.pool.sync_new_changes(incoming_blocks, all_metaslabs) self.y_flushed.append(0) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) self.pool.sync_done() self.last_incoming = incoming_blocks return nflushed = 0 if not self.last_incoming == 0: self.pool.flush_n_metaslabs(self.last_incoming) nflushed += self.last_incoming assert nflushed <= self.nmetaslabs while not self.condition_satisfied(): print "1:", len(self.pool.logs.sms[0].metaslabs_flushed), self.pool.logs.nlogs() self.pool.flush_n_metaslabs(1) nflushed += 1 print "2:", len(self.pool.logs.sms[0].metaslabs_flushed), self.pool.logs.nlogs() assert nflushed <= self.nmetaslabs assert self.condition_satisfied() ms_flushed_this_txg = self.pool.mss.ms_ordered_by_flushed[-nflushed:] self.pool.sync_new_changes(incoming_blocks, ms_flushed_this_txg) print "DBG - ", self.pool.syncing_txg, " incoming", incoming_blocks, " flushed", nflushed self.pool.sync_done() self.last_incoming = incoming_blocks self.y_flushed.append(nflushed) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) print "N", self.nmetaslabs, self.pool.logs.nblocks def simulate(self, y_incoming): for incoming in y_incoming: self.sync_cycle(incoming)
class HeuristicMTable(object): def __init__(self, nmetaslabs): self.nmetaslabs = nmetaslabs self.pool = Pool(nmetaslabs) self.y_flushed = [] self.y_blocks = [] self.y_logs = [] def condition_satisfied(self): if self.pool.mss.nmetaslabs() >= self.pool.logs.nblocks: return True return False def sync_cycle(self, incoming_blocks): if self.pool.syncing_txg == 0: all_metaslabs = self.pool.mss.ms_ordered_by_flushed self.pool.sync_new_changes(incoming_blocks, all_metaslabs) self.y_flushed.append(0) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) self.pool.sync_done() return nflushed = 0 if self.pool.syncing_txg > 768: mtable = MTable(self.pool) nflushed += mtable.getFlushesNeeded(incoming_blocks) print "M", nflushed self.pool.flush_n_metaslabs(nflushed) else: self.pool.flush_n_metaslabs(incoming_blocks) nflushed += incoming_blocks # while not self.condition_satisfied(): # self.pool.flush_n_metaslabs(1) # nflushed += 1 ms_flushed_this_txg = self.pool.mss.ms_ordered_by_flushed[-nflushed:] self.pool.sync_new_changes(incoming_blocks, ms_flushed_this_txg) print "DBG - ", self.pool.syncing_txg, " flushed", nflushed self.pool.sync_done() self.y_flushed.append(nflushed) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) def simulate(self, y_incoming): for incoming in y_incoming: self.sync_cycle(incoming)
class HeuristicSummary2(object): def __init__(self, nmetaslabs): self.nmetaslabs = nmetaslabs self.pool = Pool(nmetaslabs) self.y_flushed = [] self.y_blocks = [] self.y_logs = [] self.summary = Summary(self.pool) def condition_satisfied(self): if self.pool.mss.nmetaslabs() >= self.pool.logs.nblocks: return True return False def printAllLogs(self): print "=== DBG - PRINT LOGS - START ===" for log in self.pool.logs.sms: print "txg", log.txg, "ms", len( log.metaslabs_flushed), "blks", log.blocks print "=== DBG - PRINT LOGS - END ===" def printSummary(self): print "=== DBG - PRINT SUMMARY - START ===" for entry in self.summary.tab: print "range: {}-{}".format(entry.beginTXG, entry.endTXG) print "=== DBG - PRINT SUMMARY - END ===" def sync_cycle(self, incoming_blocks): if self.pool.syncing_txg == 0: all_metaslabs = self.pool.mss.ms_ordered_by_flushed self.pool.sync_new_changes(incoming_blocks, all_metaslabs) self.summary.updateSummary(len(all_metaslabs), 0, incoming_blocks) self.y_flushed.append(0) # Not really self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) self.pool.sync_done() return self.summary.verifySummary() nflushed = 0 nflushed += self.summary.metaslabsToFlush(incoming_blocks) print "M", nflushed self.pool.flush_n_metaslabs(nflushed) self.summary.verifySummary() ms_flushed_this_txg = self.pool.mss.ms_ordered_by_flushed[-nflushed:] self.pool.sync_new_changes(incoming_blocks, ms_flushed_this_txg) print "Y", self.y_blocks[-1], self.pool.logs.nblocks self.summary.updateSummary(nflushed, self.y_blocks[-1] - self.pool.logs.nblocks, incoming_blocks) self.printAllLogs() self.printSummary() self.summary.verifySummary() print "DBG - ", self.pool.syncing_txg, " flushed", nflushed self.pool.sync_done() self.y_flushed.append(nflushed) self.y_blocks.append(self.pool.logs.nblocks) self.y_logs.append(self.pool.logs.nlogs()) def simulate(self, y_incoming): for incoming in y_incoming: self.sync_cycle(incoming)