uw_cpus.append(Uw_cpu) Xw = getMetrics.calculate_data_incoming_rate( nodes, services["web-worker"]) #print("average data arrival rate: %f Kb/s" % (Xw)) f.write(str(Xw) + ",") xws.append(Xw) Res = getMetrics.calculate_requests_responseTime_pi() #print("response time of /dataop/pi is: %f\n" % (Res)) f.write(str(Res) + "\n") res.append(Res) print("%f,%f,%f,%f" % (CtnNum, Uw_cpu, Xw, Res)) #----------------------------------------------- ActNewCtnNum = random.randint(1, 10) settings.scale(services["web-worker"], ActNewCtnNum, 1) #----------------------------------------------------------------------------------- fig, ax1 = plt.subplots() t = range(len(ctnnums)) ax1.set_xlabel('#sample (s)') ### ax1.plot(t, ctnnums, 'b-') ax1.set_ylabel('#ctn', color='b') ax1.tick_params('y', colors='b') ### ax2 = ax1.twinx() ax2.plot(t, uw_cpus, 'r-') ax2.set_ylabel('Uw_cpu', color='r') ax2.tick_params('y', colors='r') ### ax3 = ax1.twinx()
else: mtp = abs(Xw * R_ - Uw_cpu) / (Xw * R_ * Uw_cpu) print("new number of containers should be %f x" % (mtp)) f.write("new number of containers should be %f x" % (mtp) + "\n") NewCtnNum = round(CtnNum / math.sqrt(mtp)) print( "--> Given the utilization here, we want new number of containers in this tier to be (U/(1-U)/R_): ", NewCtnNum) f.write( "--> Given the utilization here, we want new number of containers in this tier to be (U/(1-U)/R_): %d" % (NewCtnNum) + "\n") NewCtnNum = min(NewCtnNum, 15) if Uw_cpu > 0.6 and NewCtnNum > CtnNum: settings.scale(services["web-worker"], NewCtnNum, 1) elif Uw_cpu < 0.3 and NewCtnNum < CtnNum: if NewCtnNum > 0: settings.scale(services["web-worker"], NewCtnNum, -1) else: settings.scale(services["web-worker"], 1, -1) '''print("database: ") print("CPU Usage (avg): {0:.2f}%".format( getMetrics.calculate_cpu_utilization(nodes, services["mysql"]) * 100)) print("average data arrival rate: %f Kb/s\n" % ( getMetrics.calculate_data_incoming_rate(nodes, services["mysql"])))''' print("================================================") f.write("================================================" + "\n") time.sleep(50)
print("average data arrival rate: %f Kb/s\n" % (Xw)) #----------------------------------------------- if Xw == float(0): mtp = 1 else: mtp = (Xw * R_ - Uw_cpu) / (Xw * R_ * Uw_cpu) print(R_) print("new number of containers should be %f x" % (mtp)) NewCtnNum = math.ceil(CtnNum / mtp) print( "--> Given the utilization here, we want new number of containers in this tier to be (U/(1-U)/R_): ", NewCtnNum) '''NewCtnNum = (Xw * R_ - Uw_cpu) / (Xw * R_ * Uw_cpu) * CtnNum NewCtnNum = int(NewCtnNum) + 1 print(NewCtnNum)''' NewCtnNum = min(NewCtnNum, 15) if NewCtnNum > CtnNum: settings.scale(services["mysql"], NewCtnNum, 1) elif NewCtnNum < CtnNum: if NewCtnNum > 0: settings.scale(services["mysql"], NewCtnNum, -1) else: settings.scale(services["mysql"], 1, -1) '''print("database: ") print("CPU Usage (avg): {0:.2f}%".format( getMetrics.calculate_cpu_utilization(nodes, services["mysql"]) * 100)) print("average data arrival rate: %f Kb/s\n" % ( getMetrics.calculate_data_incoming_rate(nodes, services["mysql"])))''' time.sleep(5)