Пример #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
            )
Пример #2
0
 def _generateServiceProviders(self):
     np = NetworkProvider().getInstance()
     [
         np.addServiceProvider(
             ServiceProvider(self.execution_time.generate() if self.
                             execution_time else None))
         for _ in range(self.nbServiceProviders)
     ]
Пример #3
0
 def generateServiceProviders(self):
     np = NetworkProvider().getInstance()
     totalResources = np.getTotalResources()
     for _ in range(self.serviceProviders.generate()):
         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))
             for _ in range(self.containers.generate()):
                 opt.addContainer(
                     Container(self.reqResources[0].generate(),
                               self.reqResources[1].generate()))
             resources = opt.getTotalResources()
             opt.setBandwidthSaving(
                 self.bandwidth.generate(resources, totalResources))
Пример #4
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
            )