def adjustRate(routL, servrates, cusL, qTypeL, adjustIndex, maxError): #print "In adjustRate:" rateToAdjust = servrates[adjustIndex[0]][adjustIndex[1]] lamL, T = mva_multiclass(routL, servrates, cusL, qTypeL) v = 0.1 diff = lamL[0] - lamL[1] while math.fabs(diff) > maxError: #print "oldServrates:" #print servrates #print "lambda difference:" #print lamL[0] - lamL[1] if diff > 0: #(the writer is faster than the reader) rateToAdjust += v#increase the rate of the reader else: rateToAdjust -= v#decrease the rate of the reader #plug ratetoAdjust back to the rates servrates = updateRates(servrates, adjustIndex, rateToAdjust) lamL, T = mva_multiclass(routL, servrates, cusL, qTypeL) #print "newServrates:" #print servrates v = v/2 if diff == lamL[0] - lamL[1]: break diff = lamL[0] - lamL[1] return servrates
def runmepan(msg): if msg != 'imhappy': return 0 rout = [[0,1,0,0],[0,0,1,0],[0,0,0,1],[1,0,0,0]] for x in range(10,11): #print "service rate for the reader local computation: ",x servrates = np.array([[1.0,1.0],[1.0,1.0],[1.0,x],[1.0,0.7]]) la,T = mva_multiclass([rout,rout], servrates, (2,2), [1,0,1,0]) print "lambda before adjusting rates" print la[0],la[1] print "The adjusted rates for " print x newRates = adjustRate([rout,rout], servrates, (2,2), [1,0,1,0], [3,1],la[0]/100.0) print newRates l,T = mva_multiclass([rout,rout], newRates, (2,2), [1,0,1,0]) print l[0],l[1]
def mva(self, pop_vector = None): if not self.rout_l: self.analyze(self) res_tmp = mva_multiclass(self.rout_l, self.serv_rates, pop_vector or tuple(map(len, self.classes)), self.q_type) self.est_wait = res_tmp[0][1::2] self.est_qlen = res_tmp[1][1::2] self.lam = res_tmp[2]
def bodytrack(threadstuple, serv): #serv_M = ma.asarray([[0, 0, 0, 0, 6983544, 91465, 23131612, 171783], # [340208, 21308, 230049, 18250, 83687, 35901, 0, 0], # [0, 0, 0, 0, 0, 0, 22032093, 103155]]) serv_M = ma.asarray(serv) rout = [ [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 1, 1], [0, 0, 1, 0]], [[39, 1, 0, 0], [0, 4, 1, 0], [1, 0, 1, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1]] ] qt = list(islice(cycle((1,0)), serv_M.shape[1])) routL = map (lambda x: rout_insert_inter(normalizeRowWise(np.asarray(x))), rout) res = mva_multiclass (routL, 1./serv_M.T, threadstuple, qt) cont = (res[0][1::2] - serv_M.T[1::2]).T print "%.0f %.0f %.0f" % (cont[1,0], cont[0,2], cont[2,3]) return res
def streamcluster(threadstuple): #serv_M = ma.asarray([[248722, 45232],[350726, 60236]]) #serv_M = ma.asarray([[2514000, 151000],[3500000, 300000]]) serv_M = ma.asarray([[993824, 60288, ], [1397572, 60455, ], ]) rout = [[[1]], [[1]]] qt = list(islice(cycle((1,0)), serv_M.shape[1])) routL = map (lambda x: rout_insert_inter(normalizeRowWise(np.asarray(x))), rout) res = mva_multiclass (routL, 1./serv_M.T, threadstuple, qt) print (res[0][1::2] - serv_M.T[1::2]).T return res
def parse_and_run_mva (filename, nclass): '''parse service times from micro benchmark with one lock ''' nlocks = 1 nthreads = 0 if nclass > 1: serv_vec = [[],[]] wait_vec = [[],[]] else: serv_vec = [[]] wait_vec = [[]] with open(filename) as f: recReader = csv.reader (f, delimiter=' ', skipinitialspace=True) for _row in recReader: tid = int(_row[0]) think_time = float(_row[2]) q_time = float(_row[3]) serv_time = float(_row[4]) serv_vec[tid % nclass].append([think_time, serv_time]) wait_vec[tid % nclass].append(serv_time+q_time) nthreads += 1 n_per_c = nthreads arr = np.asarray(serv_vec) serv = np.average(arr, axis=1) rout = np.eye(2) routL = list(repeat(rout, nclass)) qt = list(islice(cycle((1,0)), nlocks*2)) serv_M = listOfArrToMtx(serv) res = mva_multiclass (routL, 1./serv_M.T, tuple([n_per_c]*nclass), qt) est_wait = res[0][1] meas_wait = np.average(np.array(wait_vec), axis=1) for i in xrange(nclass): print "#CLASS NTHS MEAS_S EST_W MEAS_W OFFSET MEAS_TH" print "%d %d %.0f %.0f %.0f %.0f %.0f" % (i, nthreads, serv_M.T[1][i], est_wait[i], meas_wait[i], meas_wait[i]-est_wait[i], serv_M.T[0][i]) return res