def test_sed_make_decision_heterogeneous_choose_server_1(self):
     heterogeneous_servers = simutil.init_servers(2, [1, 1], [3, 1])
     heterogeneous_servers[0]._total_jobs = 1  # Job to server 0
     self.assertEqual(heterogeneous_servers[0]._service_rate, 3)
     self.assertEqual(heterogeneous_servers[1]._service_rate, 1)
     self.assertEqual(
         self.sed_policy.make_decision(heterogeneous_servers, Job(0.2,
                                                                  0.4)), 0)
 def setUp(self):
     self.random_policy = policies.RND()
     self.shortest_queue_policy = policies.ShortestQueue()
     self.sed_policy = policies.SED()
     self.servers = simutil.init_servers(5, [1, 1, 1, 1, 1],
                                         [2, 2, 2, 2, 2])
     self.td_learn_policy = policies.TDlearning([4, 4], [], [], 100,
                                                self.servers)
    def setUp(self):
        job_size_rate = 1
        job_sizes = Expo(job_size_rate)
        seed = 500
        self.arrival = arrivals.PoissonArrival(2, job_sizes, arr_seed=seed)

        self.statistics = stats.Statistics()
        self.world = global_state.Global(self.statistics)
        self.servers = simutil.init_servers(2, [1, 1], [2, 2])  # 2 servers, both using 1 (FIFO) and both run at 2 job units service rate.
        self.dispatcher = simutil.init_dispatchers(1, [1], [self.servers], [], 725)
Ejemplo n.º 4
0
 def setUp(self):
     self.stats = stats.Statistics()
     self.world = global_state.Global(self.stats)
     job_size_rate = 1
     self.job_sizes = Expo(job_size_rate)
     arr_seed = 100
     self.p_arrivals = arrivals.PoissonArrival(2, self.job_sizes, arr_seed)
     self.list_of_servers = simutil.init_servers(1, [1], [2])
     self.policy_i = policies.ShortestQueue()
     self.d = simutil.init_dispatchers(1, [2], [self.list_of_servers], [],
                                       150)
Ejemplo n.º 5
0
def q_testing_id(id):
    sim_time = 2000000
    list_of_servers = simutil.init_servers(2, [1, 1], [3, 1])  # 2 servers using FIFO and mui = 3, and 1
    list_of_dispatchers = simutil.init_dispatchers(1, [3], [list_of_servers], [[4, 4], [], [], sim_time])  # 1 dispatcher, Qlearn, 5x5 box, nothing excluded.
    statistics = Statistics()
    world = Global(statistics)
    job_sizes = Expo(2)  # Lambda = 2,  rho will be lambda / (3+1) = 0.5
    p_arrivals = PoissonArrival(1, job_sizes)  # Poisson arrivals with 1 arrival rate.
    simutil.init_first_jobs(world, list_of_dispatchers, p_arrivals)
    # Main loop

    for x in range(1, 101):
        while world.next_event() <= float(sim_time) * (x * 0.01):  # while the virtual time of next event is less than our simulation time..
            world.process_event()  # We take the event and process it (running the function(s))
        # world._stats.write_to_file_jobs()
        print("thread id: {}, finised {}%".format(id, x))
        if(x % 5 == 0):
            v2 = list_of_dispatchers[0]._policy.v2
            with open('../data_results/TD_learn_server_utilization/2Mjobs_TD_alpha_decay_rho_' + str(id) + '.txt', 'a') as f:
                for key in v2:
                    f.write(str(key) + ': ' + str(v2[key]) + '\n')
                f.write('\n')
Ejemplo n.º 6
0
def td_learn_server_utilization(rho, round_nr):
    sim_time = 5000000
    list_of_servers = simutil.init_servers(2, [1, 1], [3, 1])  # 2 servers using FIFO and mui = 3, and 1
    list_of_dispatchers = simutil.init_dispatchers(1, [3], [list_of_servers], [[12, 4], [], [], sim_time])  # 1 dispatcher, Qlearn, 5x5 box, nothing excluded.
    statistics = Statistics()
    world = Global(statistics)
    # arrival_rate = 2  # get the arrival rate by using given rho
    job_sizes = Expo(1)  # Lambda = 2,  rho will be lambda / (3+1) = 0.5
    p_arrivals = PoissonArrival(3.92, job_sizes)  # Poisson arrivals with 1 arrival rate.
    simutil.init_first_jobs(world, list_of_dispatchers, p_arrivals)
    # Main loop

    for x in range(1, 101):
        while world.next_event() <= float(sim_time) * (x * 0.01):  # while the virtual time of next event is less than our simulation time..
            world.process_event()  # We take the event and process it (running the function(s))
        # world._stats.write_to_file_jobs()
        print("round: {}, rho: {}, finised {}%".format(round_nr, rho, x))

    v2 = list_of_dispatchers[0]._policy.v2
    with open('../data_results/TD_learn_server_utilization/500kjobs_SED_rho_' + str(rho) + '-3.txt', 'a') as f:
        for key in v2:
            f.write(str(key) + ': ' + str(v2[key]) + '\n')
        f.write('\n')
Ejemplo n.º 7
0
def TD_testing(st,
               servers,
               dispatchers,
               arrival_rate,
               job_size_rate,
               job_distribution,
               qlearn,
               arrivals_seed=None,
               policyseed=None,
               file_name=None,
               td_matrix=None):
    sim_time = st
    list_of_servers = simutil.init_servers(
        len(servers[0]), servers[0],
        servers[1])  # List of servers for 1 dispatcher
    servers_for_dispatchers = []
    servers_for_dispatchers.append(list_of_servers)
    list_of_dispatchers = simutil.init_dispatchers(
        dispatchers[0],
        dispatchers[1],
        servers_for_dispatchers,
        qlearn,
        policyseed,
        td_matrix_and_backup=[
            td_matrix, SED(policyseed)
        ])  # 1 dispatcher, Qlearn, 5x5 box, nothing excluded.
    statistics = Statistics()
    world = Global(statistics)
    if job_distribution == 1:
        job_sizes = Expo(job_size_rate)
    if file_name is not None:
        print("file name used")
        f = open(file_name, 'r')
        data = f.read().splitlines()
        sim_time = int(data[-1])
        print(sim_time)
        data2 = [
            tuple(float(x) for x in item.split(',')) for item in data[:-1]
        ]
        p_arrivals = PoissonArrival(
            arrival_rate, job_sizes, arrivals_seed,
            file=data2)  # Poisson arrivals with arrival rate 1.
    else:
        p_arrivals = PoissonArrival(
            arrival_rate, job_sizes,
            arrivals_seed)  # Poisson arrivals with arrival rate 1.

    simutil.init_first_jobs(world, list_of_dispatchers, p_arrivals)
    # Main loop
    start = timer()
    for x in range(1, 101):
        while world.next_event() <= float(sim_time) * (
                x * 0.01
        ):  # while the virtual time of next event is less than our simulation time..
            world.process_event(
            )  # We take the event and process it (running the function(s))
        print("{}%".format(x))
    end = timer()
    print("Total time: {}".format(end - start))
    if dispatchers[1] == 3:
        print('The state counter: ' +
              str(list_of_dispatchers[0]._policy.state_counter))
    total_no_jobs = world._stats.number_of_jobs
    print(total_no_jobs)
    # simutil.print_step_matrix(list_of_dispatchers[0])
    world._stats.print_stats()
    world._stats.save_run(sim_time)
    simutil.save_stats(world)  # Ask user if he wants to save stats to file
Ejemplo n.º 8
0
 def setUp(self):
     self.servers = simutil.init_servers(2, [1, 1], [2, 2])  # 2 servers, both using 1 (FIFO) and both run at 2 job units service rate.
     self.dispatchers = simutil.init_dispatchers(1, [1], [self.servers], [])
     self.dispatcher = self.dispatchers[0]