예제 #1
0
  def __init__(self,params):
    number_of_servers=int(params["number_of_servers"])

    self.number_of_requests = int(params["number_of_requests"])
    self.number_of_types = len(params["types_of_requests"])

    self.number_of_requests_per_sec = int(params["number_of_requests_per_sec"])
    self.generator = RequestGenerator(params["types_of_requests"],int(params["number_of_requests_per_sec"]))

    request_type_capacity=[x["output_capacity"] for x in params["types_of_requests"].values()]
    server_capacity = self.distribute_output_capacity(number_of_servers,request_type_capacity)
     
    #print "server capacity:", server_capacity

    servers = [Server(server_capacity[z]) for z in range(number_of_servers)]
    self.loadbalancer = LoadBalancer(servers=servers,method=params["method"])
    def main_func(self):
        if os.path.isfile('config.yaml'):  #if config file is there but empty
            self._key = ConfigReader().getKey()
            if not self._key:
                self.keyConfig
            self.location = input('Enter location ').strip().lower()
        else:  #if there is no config file then create one
            self.keyConfig
            self.location = input('Enter location ').strip().lower()

        self.location_encoded = urllib.parse.quote(self.location)
        self.URLGenerator_obj = URLGenerator(user_api=self._key,
                                             location=self.location_encoded)
        self.RequestGenerator_obj = RequestGenerator(self.URLGenerator_obj)
        self.DataFetcher_obj = DataFetcher(self.RequestGenerator_obj,
                                           location=self.location)
        self.DataFetcher_obj.getData()

        print('Print data to a CSV file?(Y/N)')
        if input() == 'Y':
            self.DataFetcher_obj.exportData()
            self._restartApp()
        else:
            self._restartApp()
예제 #3
0
class Simulator:

  def __init__(self,params):
    number_of_servers=int(params["number_of_servers"])

    self.number_of_requests = int(params["number_of_requests"])
    self.number_of_types = len(params["types_of_requests"])

    self.number_of_requests_per_sec = int(params["number_of_requests_per_sec"])
    self.generator = RequestGenerator(params["types_of_requests"],int(params["number_of_requests_per_sec"]))

    request_type_capacity=[x["output_capacity"] for x in params["types_of_requests"].values()]
    server_capacity = self.distribute_output_capacity(number_of_servers,request_type_capacity)
     
    #print "server capacity:", server_capacity

    servers = [Server(server_capacity[z]) for z in range(number_of_servers)]
    self.loadbalancer = LoadBalancer(servers=servers,method=params["method"])
  
  def distribute_output_capacity(self,number_of_servers,type_capacity):
    server_capacity = [[0 for z in range(self.number_of_types)]
      for server in range(number_of_servers)]

    for z in range(self.number_of_types):
      while (type_capacity[z]>0):
        for server in range(number_of_servers):
          if type_capacity[z] <= 0:
            break
          server_capacity[server][z]+=1
          type_capacity[z]-=1

    return server_capacity
        
  def number_of_servers(self):
    return self.loadbalancer.number_of_servers()

  def total_service_time(self):
    return self.loadbalancer.total_service_time()

  def total_wait_time(self):
    return self.loadbalancer.total_wait_time()

  def total_wait_requests(self):
    return self.loadbalancer.total_wait_requests()

  def number_of_requests_per_type(self):
    return self.loadbalancer.number_of_requests_per_type()

  def number_of_failed_requests_per_type(self):
    return self.loadbalancer.number_of_failed_requests_per_type()

  def simulate(self):
    arrival_time = 0
    reqno = 0
    while True:     
       for req in self.generator.generate(number_of_requests=100):
         reqno += 1
         request_type,delay,service_time=req
         arrival_time += delay

         #print "--- %s arrive at %f" % (request_type,arrival_time)
         self.loadbalancer.process(request_type,arrival_time,service_time)

       if  reqno >=self.number_of_requests:
          break