コード例 #1
0
ファイル: dataGathering.py プロジェクト: XMK233/EECS6432
    # cpu usage api is not fast. be patient!
    # here we consistently get the cpu usage of all the web-workers and calculate the average

    R_ = settings.target_response_time

    start_time = datetime.datetime.now()
    time_limit = datetime.timedelta(seconds=4300)
    print("let's get started")
    with open("dataop-pi_data-gathering_%s.csv" %(start_time.strftime("%Y-%m-%d_%H-%M-%S")), "w") as f:
        while True:

            now_time = datetime.datetime.now()
            if now_time - start_time >= time_limit:
                break

            Uw_cpu = getMetrics.calculate_cpu_utilization(nodes, services["web-worker"])
            Xw = getMetrics.calculate_data_incoming_rate(nodes, services["web-worker"])
            data = [now_time.strftime("%Y-%m-%d %H:%M:%S"), str(Uw_cpu), str(Xw)]
            hehe = ",".join(data)
            print(hehe)
            f.write(hehe + "\n")

            '''Um_cpu = getMetrics.calculate_cpu_utilization(nodes, services["mysql"])
            Xm = getMetrics.calculate_data_incoming_rate(nodes, services["mysql"])
            data = [now_time.strftime("%Y-%m-%d %H:%M:%S"), str(Um_cpu), str(Xm)]
            hehe = ",".join(data)
            print(hehe)
            f.write(hehe + "\n")'''

            time.sleep(5)
コード例 #2
0
    # get the tasks running on our swarm cluster
    for service_name, service in services.items():
        settings.get_tasks(service)

    # cpu usage api is not fast. be patient!
    # here we consistently get the cpu usage of all the web-workers and calculate the average

    R_ = settings.target_response_time

    while True:
        print("======================mysql server: ==========================")

        CtnNum = settings.get_tasks(services["mysql"])
        print("Originally, this tier has %d containers" % (CtnNum))

        Uw_cpu = getMetrics.calculate_cpu_utilization(nodes, services["mysql"])
        print("CPU Usage (avg): {0:.2f}%".format(Uw_cpu * 100))

        Xw = getMetrics.calculate_data_incoming_rate(nodes, services["mysql"])
        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_): ",