Beispiel #1
0
    def generateServiceProviders(self):
        np = NetworkProvider().getInstance()
        totalResources = np.getTotalResources()
        #while(self._K * np.getTotalResources()[0] > np.getSumAverageRequiredResources()[0] or
        # while k_ram < 1.8 || k_cpu < 1.8
        # k_ram = k_cpu
        for _ in range(self.serviceProviders.generate()):
        #    self._K * np.getTotalResources()[1] > np.getSumAverageRequiredResources()[1]):
            sp = np.addServiceProvider(ServiceProvider(self.execution_time.generate() if self.execution_time else None))
            for _ in range(self.options.generate()):
                opt = sp.addOption(Option(sp))
                rjob = random_job.random_job()
                for count, task in enumerate(rjob.itertuples()):
                    opt.addContainer(Container(task.CPU, task.memory))
                resources = opt.getTotalResources()
                opt.setBandwidthSaving(self.bandwidth.generate(resources, totalResources))

        avgZ = 0
        for sp in np.getServiceProviders():
            for opt in sp.getOptions():
                avgZ += len(opt.getContainers())
        avgZ /= len(np.getServiceProviders()) * len(np.getServiceProviders()[0].getOptions())

        self._K = \
            (
                np.getSumAverageRequiredResources()[0]/np.getTotalResources()[0] * len(np.getServiceProviders()) * avgZ,
                np.getSumAverageRequiredResources()[1]/np.getTotalResources()[1] * len(np.getServiceProviders()) * avgZ
            )
Beispiel #2
0
 def _generateRequiredResources(self):
     np = NetworkProvider().getInstance()
     for sp in np.getServiceProviders():
         for opt in sp.getOptions():
             for ct in opt.getContainers():
                 ct.setCpuReq(self.reqResources[0].generate())
                 ct.setRamReq(self.reqResources[1].generate())
Beispiel #3
0
 def _generateContainers(self):
     np = NetworkProvider().getInstance()
     for sp in np.getServiceProviders():
         for opt in sp.getOptions():
             rjob = random_job.random_job()
             for task in rjob.itertuples():
                 opt.addContainer(Container(task.CPU*100, task.memory*100))
Beispiel #4
0
 def _generateBandwidthSaving(self):
     np = NetworkProvider().getInstance()
     totalResources = np.getTotalResources()
     for sp in np.getServiceProviders():
         for opt in sp.getOptions():
             resources = opt.getTotalResources()
             opt.setBandwidthSaving(self.bandwidth.generate(resources, totalResources))
Beispiel #5
0
 def _generateContainers(self):
     np = NetworkProvider().getInstance()
     for sp in np.getServiceProviders():
         for opt in sp.getOptions():
             [
                 opt.addContainer(Container(0, 0))
                 for _ in range(self.containers.generate())
             ]
Beispiel #6
0
 def save_to_csv(self, suffix=""):
     np = NetworkProvider().getInstance()
     df = pd.DataFrame(columns=["sp", "opt", "container", "cpu", "ram", "cpu_tot_opt", "ram_tot_opt", "utility_opt"])
     for i, sp in enumerate(np.getServiceProviders()):
         for j, opt in enumerate(sp.getOptions()):
             for k, container in enumerate(opt.getContainers()):
                 df.loc[len(df)] = {
                     "sp": i,
                     "opt": j,
                     "container": k,
                     "cpu": container.getCpuReq(),
                     "ram": container.getRamReq(),
                     "cpu_tot_opt": opt.getCpuReq(),
                     "ram_tot_opt": opt.getRamReq(),
                     "utility_opt": opt.getBandwidthSaving()
                 }
     df.to_csv("results/google_traces_scenario_%d_sp_%d_opt_%s.csv" %
               (len(np.getServiceProviders()), len(np.getServiceProviders()[0].getOptions()), suffix))
Beispiel #7
0
 def save_for_ilp(self, options_slice=1):
     np = NetworkProvider().getInstance()
     f = open("scenario.dat", "w+")
     f.write(f"param K := {self._K};\n")
     f.write(f"param nbServers := {len(np.getServers())};\n")
     f.write(f"param nbResources := 2;\n")
     f.write(
         f"param nbServiceProviders := {len(np.getServiceProviders())};\n")
     f.write("param availableResources :=")
     availableResources = {}
     for i, server in enumerate(np.getServers()):
         availableResources[i, 0] = server.getTotalCpu()
         availableResources[i, 1] = server.getTotalRam()
     f.write(self._printDict(availableResources))
     f.write("\n;\nparam nbOptions :=")
     options = []
     for i, sp in enumerate(np.getServiceProviders()):
         options.append(len(sp.getOptions()[0:options_slice]))
     f.write(self._printArray(options))
     f.write("\n;\nparam bandwidthSaving :=")
     bandwidthSaving = {}
     for i, sp in enumerate(np.getServiceProviders()):
         for j, opt in enumerate(sp.getOptions()[0:options_slice]):
             bandwidthSaving[i, j] = opt.getBandwidthSaving()
     f.write(self._printDict(bandwidthSaving))
     f.write("\n;\nparam nbContainers :=")
     containers = {}
     for i, sp in enumerate(np.getServiceProviders()):
         for j, opt in enumerate(sp.getOptions()[0:options_slice]):
             containers[i, j] = len(opt.getContainers())
     f.write(self._printDict(containers))
     f.write("\n;\nparam requiredResources :=")
     requiredResources = {}
     for i, sp in enumerate(np.getServiceProviders()):
         for j, opt in enumerate(sp.getOptions()[0:options_slice]):
             for k, container in enumerate(opt.getContainers()):
                 requiredResources[i, j, k, 0] = container.getCpuReq()
                 requiredResources[i, j, k, 1] = container.getRamReq()
     f.write(self._printDict(requiredResources))
     f.write("\n;\n\r")
     f.close()
Beispiel #8
0
    def generateServiceProviders(self):
        print("Generating Service providers")
        np = NetworkProvider().getInstance()
        totalResources = np.getTotalResources()
        #while(self._K * np.getTotalResources()[0] > np.getSumAverageRequiredResources()[0] or
        # while k_ram < 1.8 || k_cpu < 1.8
        # k_ram = k_cpu

        container_meta = pd.read_csv("datasets-alibaba/container_meta.csv",
                                     header=None)
        container_usage = pd.read_csv(
            "datasets-alibaba/container_usage_5mins.csv", header=None)
        print("CSVs read")
        apps = list(container_meta.loc[:, 3].unique())

        print("Entering the loop")
        for _ in range(self.serviceProviders.generate()):
            #    self._K * np.getTotalResources()[1] > np.getSumAverageRequiredResources()[1]):
            sp = np.addServiceProvider(
                ServiceProvider(self.execution_time.generate() if self.
                                execution_time else None))
            for _ in range(self.options.generate()):
                print("Generating option")

                notFound = True

                opt = sp.addOption(Option(sp))
                while (notFound):

                    app_du = apps.pop(Random.randint(0, len(apps)))

                    containers = container_meta.loc[container_meta[3] ==
                                                    app_du]

                    containers_ids = list(containers.loc[:, 0].unique())

                    #rjob = random_job.random_job()
                    bw = 0
                    for container in containers_ids:
                        print("Inserting container")
                        ctmp = containers.loc[containers[0] == container].head(
                            1)
                        ctmp2 = container_usage[container_usage[0] ==
                                                container]
                        if len(ctmp2) == 0:
                            continue
                        notFound = False
                        opt.addContainer(
                            Container(  #int(ctmp2[3].mean()), int(ctmp2[4].mean())))
                                int(ctmp[5]), int(ctmp[7])))
                        bw += ctmp2[8].mean() + ctmp2[9].mean()
                    opt.setBandwidthSaving(bw)

        avgZ = 0
        for sp in np.getServiceProviders():
            for opt in sp.getOptions():
                avgZ += len(opt.getContainers())
        avgZ /= len(np.getServiceProviders()) * len(
            np.getServiceProviders()[0].getOptions())

        self._K = \
            (
                np.getSumAverageRequiredResources()[0]/np.getTotalResources()[0] * len(np.getServiceProviders()) * avgZ,
                np.getSumAverageRequiredResources()[1]/np.getTotalResources()[1] * len(np.getServiceProviders()) * avgZ
            )
Beispiel #9
0
 def _generateOptions(self):
     np = NetworkProvider().getInstance()
     for sp in np.getServiceProviders():
         for i in range(self.options.generate()):
             sp.addOption(Option(sp))